{"id":18048066,"url":"https://github.com/ivangfr/spring-data-jpa-relationships","last_synced_at":"2025-10-19T11:54:47.548Z","repository":{"id":162443402,"uuid":"635522632","full_name":"ivangfr/spring-data-jpa-relationships","owner":"ivangfr","description":"The goal of this project is to study the JPA relationships: one-to-one, one-to-many / many-to-one, and many-to-many.","archived":false,"fork":false,"pushed_at":"2024-12-17T20:45:10.000Z","size":320,"stargazers_count":30,"open_issues_count":0,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T08:42:34.271Z","etag":null,"topics":["java","jpa-relationships","many-to-many","many-to-one","mapstruct","one-to-many","one-to-one","postgresql","spring-boot","spring-data-jpa","spring-web-mvc","springdoc-openapi","testcontainers"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivangfr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ivangfr"}},"created_at":"2023-05-02T21:59:20.000Z","updated_at":"2025-01-26T17:27:28.000Z","dependencies_parsed_at":"2024-10-30T20:21:21.582Z","dependency_job_id":null,"html_url":"https://github.com/ivangfr/spring-data-jpa-relationships","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivangfr%2Fspring-data-jpa-relationships","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivangfr%2Fspring-data-jpa-relationships/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivangfr%2Fspring-data-jpa-relationships/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivangfr%2Fspring-data-jpa-relationships/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivangfr","download_url":"https://codeload.github.com/ivangfr/spring-data-jpa-relationships/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248197336,"owners_count":21063619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jpa-relationships","many-to-many","many-to-one","mapstruct","one-to-many","one-to-one","postgresql","spring-boot","spring-data-jpa","spring-web-mvc","springdoc-openapi","testcontainers"],"created_at":"2024-10-30T20:11:14.260Z","updated_at":"2025-10-19T11:54:47.542Z","avatar_url":"https://github.com/ivangfr.png","language":"Java","funding_links":["https://github.com/sponsors/ivangfr"],"categories":[],"sub_categories":[],"readme":"# spring-data-jpa-relationships\n\nThe goal of this project is to study the JPA relationships: `one-to-one`, `one-to-many` / `many-to-one`, and `many-to-many`.\n\n## Proof-of-Concepts \u0026 Articles\n\nOn [ivangfr.github.io](https://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.\n\n## Additional Readings\n\n- \\[**Medium**\\] [**Understanding Relationships in JPA: Introduction**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-introduction-5416c8a7c8a9)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: One-to-One with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-one-with-simple-primary-key-7c32f7e13a6a)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: One-to-One with Shared Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-one-with-shared-primary-key-36596416fe56)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: One-to-Many with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-many-with-simple-primary-key-e2e975c67c31)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: One-to-Many with Composite Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-many-with-composite-primary-key-1d7724a2bf63)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-simple-primary-key-b38209e5c9b4)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Simple Primary Key and Extra Column**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-simple-primary-key-and-extra-column-817e8bdda465)\n- \\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Composite Primary Key and Extra Column**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-composite-primary-key-and-extra-column-a939b107c7cd)\n- \\[**Medium**\\] [**Mastering JPA Relationships: Practical Examples of Bidirectional Associations**](https://medium.com/@ivangfr/spring-data-jpa-6bb5cd745b46)\n\n## Prerequisites\n\n- [`Java 21`](https://www.oracle.com/java/technologies/downloads/#java21) or higher;\n- A containerization tool (e.g., [`Docker`](https://www.docker.com), [`Podman`](https://podman.io), etc.)\n\n## Start Environment\n\nIn a terminal and inside the `spring-data-jpa-relationships` root folder, run the following command:\n```bash\ndocker compose up -d\n```\n\n## Running application using Maven\n\nIn a terminal and inside the `spring-data-jpa-relationships` root folder, run the command below:\n```bash\n./mvnw clean spring-boot:run\n```\n\nOnce the application is running, you can access its Swagger website at http://localhost:8080/swagger-ui.html.\n\n## Useful Commands\n\n- **Postgres**\n  ```bash\n  docker exec -it postgres psql -U postgres -d jparelationshipsdb\n  \\d persons\n  select * from persons;\n  ```\n  \u003e Type `exit` to exit\n\n## Shutdown\n\n- To stop the application, go to the terminal where it is running and press `Ctrl+C`;\n- 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:\n  ```bash\n  docker compose down -v\n  ```\n\n## Running Tests\n\nIn a terminal and inside the `spring-data-jpa-relationships` root folder, run the following command:\n```bash\n./mvnw clean test\n```\n\n## JPA relationships\n\n### One-to-One with Simple Primary Key\n\n![teams_team_details](documentation/teams_team_details.png)\n\n\\[**Medium**\\]: [**Understanding Relationships in JPA: One-to-One with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-one-with-simple-primary-key-7c32f7e13a6a)\n\n### One-to-One with Shared Primary Key\n\n![persons_person_details](documentation/persons_person_details.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: One-to-One with Shared Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-one-with-shared-primary-key-36596416fe56)\n\n### One-to-Many with Simple Primary Key\n\n![restaurants_dishes](documentation/restaurants_dishes.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: One-to-Many with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-many-with-simple-primary-key-e2e975c67c31)\n\n### One-to-Many with Composite Primary Key\n\n![players_weapons](documentation/players_weapons.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: One-to-Many with Composite Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-one-to-many-with-composite-primary-key-1d7724a2bf63)\n\n### Many-to-Many with Simple Primary Key\n\n![writers_books](documentation/writers_books.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Simple Primary Key**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-simple-primary-key-b38209e5c9b4)\n\n### Many-to-Many with Simple Primary Key and Extra Column\n\n![reviewers_articles](documentation/reviewers_comments_articles.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Simple Primary Key and Extra Column**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-simple-primary-key-and-extra-column-817e8bdda465)\n\n### Many-to-Many with Composite Primary Key and Extra Column\n\n![students_courses](documentation/students_courses.png)\n\n\\[**Medium**\\] [**Understanding Relationships in JPA: Many-to-Many with Composite Primary Key and Extra Column**](https://medium.com/@ivangfr/understanding-relationships-in-jpa-many-to-many-with-composite-primary-key-and-extra-column-a939b107c7cd)\n\n## References\n\nOne-to-One \n- https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate\n- https://www.callicoder.com/hibernate-spring-boot-jpa-one-to-one-mapping-example/\n\nOne-to-Many / Many-to-One\n- https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate\n- https://www.callicoder.com/hibernate-spring-boot-jpa-one-to-many-mapping-example/\n\nMany-to-Many\n- https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate\n- https://www.callicoder.com/hibernate-spring-boot-jpa-many-to-many-mapping-example/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivangfr%2Fspring-data-jpa-relationships","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivangfr%2Fspring-data-jpa-relationships","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivangfr%2Fspring-data-jpa-relationships/lists"}