Skip to content

This is a simple implementation of the closure table pattern for SpringBoot with Hibernate

Notifications You must be signed in to change notification settings

bennyz327/SpringBoot-Hibernate-ClosureTable-Example

Repository files navigation

Closure Table Implementation For Spring Data JPA

English | 中文

This is a simple implementation of the closure table pattern for Spring Data JPA. The closure table pattern is a way to store hierarchical data in a relational database. It is a simple and efficient way to store and query hierarchical data.

Table of Contents

Tech Stack

  • Java 17
  • Kotlin 1.9.25
  • Spring Boot 3.3.5
  • Spring Web
  • Spring Data JPA
  • PostgreSQL 16.4

Getting Started

database setup

docker run \
-e POSTGRES_DB=test \
-e POSTGRES_PASSWORD=dev \
-e POSTGRES_USER=dev \
-p 5432:5432 \
postgres:16.4 -d

API Description

Create

root department

curl -X POST "http://localhost:8080/departments?name=dep1"

department with parent

curl -X POST "http://localhost:8080/departments?name=dep2&parentId=1"

Find

full departments tree

curl -X GET "http://localhost:8080/departments/tree"

department tree by id

curl -X GET "http://localhost:8080/departments/1/tree"

Move

move department

curl -X POST "http://localhost:8080/departments/2/move?newParentId=3"

Delete

delete department and all children

curl -X DELETE "http://localhost:8080/departments/2?strategy=CASCADE"

About

This is a simple implementation of the closure table pattern for SpringBoot with Hibernate

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages