EntityGraph fetches same relation multiple times [DATAJPA-1123] #1468
Labels
in: core
Issues in core support
status: declined
A suggestion or change that we don't feel we should currently apply
type: bug
A general bug
Yan Tuizhi opened DATAJPA-1123 and commented
Assuming I have the following entites
which I want to fetch via a
@EntityGraph
annotation on a repository method. All assocations are set toFetchType.LAZY
. The repository method is defined the following way:If there is one house with one room and three doors, then this repository method will return
This is what I would expect as result of a SQL query, when joining over all three tables. But is this also the intended behaviour of a repository? I think it is not. The ORM should handle the relations correctly. And indeed, when setting all associations to
FetchType.EAGER
and calling the repository methodfindAll()
, only one house is fetched with one room and three doors. Of course I could changeList<House>
toSet<House>
as return type of the repository method defined above, but the repository nevertheless tries to add the same house three times. Furthermore, I need lists for some operations.I see three possible solutions:
The last option subsumes both the first and the second one (the first and second option are special cases of the third one) and would be in my opinion the best solution. Sometimes it is much more performant to partition the fetching of a complex graph, especially if the graph is complex and there are many relations.
Affects: 1.11.3 (Ingalls SR3)
The text was updated successfully, but these errors were encountered: