The goal of this project is to study the JPA relationships: one-to-one
, one-to-many
/ many-to-one
, and many-to-many
.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
- [Medium] Understanding Relationships in JPA: Introduction
- [Medium] Understanding Relationships in JPA: One-to-One with Simple Primary Key
- [Medium] Understanding Relationships in JPA: One-to-One with Shared Primary Key
- [Medium] Understanding Relationships in JPA: One-to-Many with Simple Primary Key
- [Medium] Understanding Relationships in JPA: One-to-Many with Composite Primary Key
- [Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key
- [Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key and Extra Column
- [Medium] Understanding Relationships in JPA: Many-to-Many with Composite Primary Key and Extra Column
- [Medium] Mastering JPA Relationships: Practical Examples of Bidirectional Associations
In a terminal and inside the spring-data-jpa-relationships
root folder, run the following command:
docker compose up -d
In a terminal and inside the spring-data-jpa-relationships
root folder, run the command below:
./mvnw clean spring-boot:run
Once the application is running, you can access its Swagger website at http://localhost:8080/swagger-ui.html.
- Postgres
docker exec -it postgres psql -U postgres -d jparelationshipsdb \d persons select * from persons;
Type
exit
to exit
- To stop the application, go to the terminal where it is running and press
Ctrl+C
; - To stop and remove docker compose containers, network and volumes, go to a terminal and, inside the
spring-data-jpa-relationships
root folder, run the following command:docker compose down -v
In a terminal and inside the spring-data-jpa-relationships
root folder, run the following command:
./mvnw clean test
[Medium]: Understanding Relationships in JPA: One-to-One with Simple Primary Key
[Medium] Understanding Relationships in JPA: One-to-One with Shared Primary Key
[Medium] Understanding Relationships in JPA: One-to-Many with Simple Primary Key
[Medium] Understanding Relationships in JPA: One-to-Many with Composite Primary Key
[Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key
[Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key and Extra Column
[Medium] Understanding Relationships in JPA: Many-to-Many with Composite Primary Key and Extra Column
One-to-One
- https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate
- https://www.callicoder.com/hibernate-spring-boot-jpa-one-to-one-mapping-example/
One-to-Many / Many-to-One
- https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate
- https://www.callicoder.com/hibernate-spring-boot-jpa-one-to-many-mapping-example/
Many-to-Many