{"id":16620018,"url":"https://github.com/cepr0/duplicate-parent-entities","last_synced_at":"2026-05-19T10:34:33.725Z","repository":{"id":130472156,"uuid":"119599907","full_name":"Cepr0/duplicate-parent-entities","owner":"Cepr0","description":"Spring Data JPA - duplicated parent entities in 'join fetch' repository query methods","archived":false,"fork":false,"pushed_at":"2018-03-21T21:34:59.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T07:19:21.786Z","etag":null,"topics":["duplicates","spring-boot","spring-data-jpa"],"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/Cepr0.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2018-01-30T22:01:36.000Z","updated_at":"2019-03-28T13:34:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"679c2d2b-754f-4ffa-8a15-76d423a9d084","html_url":"https://github.com/Cepr0/duplicate-parent-entities","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Cepr0/duplicate-parent-entities","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fduplicate-parent-entities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fduplicate-parent-entities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fduplicate-parent-entities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fduplicate-parent-entities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cepr0","download_url":"https://codeload.github.com/Cepr0/duplicate-parent-entities/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fduplicate-parent-entities/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266839172,"owners_count":23993053,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["duplicates","spring-boot","spring-data-jpa"],"created_at":"2024-10-12T02:43:17.575Z","updated_at":"2026-05-19T10:34:33.684Z","avatar_url":"https://github.com/Cepr0.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Spring Data JPA - duplicated parent entities in 'join fetch' repository query methods \n\nRepository query methods with 'join fetch' leads to the duplicate parents.\nNumber of duplicates corresponds to number of nested children.\n\nTo workaround this situation we can use 'distinct' in the query.\nBut this still does not work with projection.\n\nThe similar methods with `@EntityGraph` work as expected.\n\nExample:\n\n```java\n@Entity\nclass Parent extends BaseEntity {\n\tprivate String name;\n\t@OneToMany(mappedBy = \"parent\")\n\tprivate List\u003cChild\u003e children;\n}\n\n@Entity\nclass Child extends BaseEntity {\n\tprivate String name;\n\t@ManyToOne(fetch = LAZY)\n\tprivate Parent parent;\n}\n\ninterface ParentProjection {\n\tInteger getId();\n\tString getName();\n\tList\u003cChild\u003e getChildren();\n}\n\ninterface ParentRepo extends JpaRepository\u003cParent, Integer\u003e {\n\n\t@EntityGraph(attributePaths = \"children\")\n\t@Override\n\tList\u003cParent\u003e findAll(); // work as expected \n\n\t@Query(\"select p from Parent p left join fetch p.children\")\n\tList\u003cParent\u003e findWithQuery(); // has duplicated parents\n\t\n\t@Query(\"select distinct p from Parent p left join fetch p.children\")\n   \tList\u003cParent\u003e findDistinctWithQuery(); // does not have duplicated parents\n\t\n\t@EntityGraph(attributePaths = \"children\")\n\tList\u003cParentProjection\u003e findProjectionsBy(); // work as expected\n\t\t\n\t@Query(\"select distinct p from Parent p left join fetch p.children\")\n   \tList\u003cParentProjection\u003e findDistinctProjectionsWithQuery(); // has duplicated parents \n}\n```   \n    \nMore tests is ![here](src/test/java/io/github/cepr0/demo/repo/ParentRepoTest.java).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fduplicate-parent-entities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcepr0%2Fduplicate-parent-entities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fduplicate-parent-entities/lists"}