Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to LEFT JOIN FETCH for @EntityGraph [DATAJPA-1124] #1469

Closed
spring-projects-issues opened this issue May 25, 2017 · 1 comment
Closed
Assignees
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Yan Tuizhi opened DATAJPA-1124 and commented

Assuming I have the following entites

abstract House (rooms)  <- Shop extends House (shopWindows)

and a repository JpaRepository<House, Long>. If want to fetch all houses with all associations, this is currently not possbile with the @EntityGraph annotation. If i have the following method in the repository:

@EntityGraph(attributePaths = {"rooms", "shopWindows"})
@Query("FROM House")
Set<House> findAllWithDependencies()

then an exception will be thrown (shopWindows is not a property of House). However, if I set all assocations to FetchType.EAGER und use the findAll method, all Shop instances are found with all assocations.

It would be very helpful (especially for real world scenarios with complex inheritance relations), if the repository would automatically detect whether a given attributePath belongs to derived class and would in that case make a LEFT JOIN FETCH. This should also be possbile for all levels of association (e.g. in case there are different types of Room or ShopWindow).

My current workaround is the following:

@EntityGraph(attributePaths = {"rooms"})
@Query("FROM House H LEFT JOIN FETCH H.shopWindows")
Set<House> findAllWithDependencies()

Alternatively, I guess I could create a repository for each derived class, but that would duplicate a lot of code.


Affects: 1.11.3 (Ingalls SR3)

@spring-projects-issues
Copy link
Author

Jens Schauder commented

The entity graph doesn't match the query so the JPA implementation throws an exception.

Spring Data is not going to try to fix incompatible combinations of entity graph and query

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core support labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants