ivangfr / spring-data-jpa-relationships

The goal of this project is to study the JPA relationships: one-to-one, one-to-many / many-to-one, and many-to-many.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-data-jpa-relationships

The goal of this project is to study the JPA relationships: one-to-one, one-to-many / many-to-one, and many-to-many.

Proof-of-Concepts & Articles

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.

Additional Readings

Prerequisites

Start Environment

In a terminal and inside spring-data-jpa-relationships root folder, run the following command

docker compose up -d

Running application using Maven

In a terminal and inside 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

Useful Commands

  • Postgres
    docker exec -it postgres psql -U postgres -d jparelationshipsdb
    \d persons
    select * from persons;
    

    Type exit to exit

Shutdown

  • 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 spring-data-jpa-relationships root folder, run the following command
    docker compose down -v
    

Running Tests

In a terminal and inside spring-data-jpa-relationships root folder, run the following command

./mvnw clean test

JPA relationships

One-to-One with Simple Primary Key

teams_team_details

[Medium]: Understanding Relationships in JPA: One-to-One with Simple Primary Key

One-to-One with Shared Primary Key

persons_person_details

[Medium] Understanding Relationships in JPA: One-to-One with Shared Primary Key

One-to-Many with Simple Primary Key

restaurants_dishes

[Medium] Understanding Relationships in JPA: One-to-Many with Simple Primary Key

One-to-Many with Composite Primary Key

players_weapons

[Medium] Understanding Relationships in JPA: One-to-Many with Composite Primary Key

Many-to-Many with Simple Primary Key

writers_books

[Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key

Many-to-Many with Simple Primary Key and Extra Column

reviewers_articles

[Medium] Understanding Relationships in JPA: Many-to-Many with Simple Primary Key and Extra Column

Many-to-Many with Composite Primary Key and Extra Column

students_courses

[Medium] Understanding Relationships in JPA: Many-to-Many with Composite Primary Key and Extra Column

References

One-to-One

One-to-Many / Many-to-One

Many-to-Many

About

The goal of this project is to study the JPA relationships: one-to-one, one-to-many / many-to-one, and many-to-many.


Languages

Language:Java 100.0%