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

Allow @EntityGraph on a method inherited from JpaRepository [DATAJPA-612] #997

Closed
spring-projects-issues opened this issue Oct 1, 2014 · 7 comments
Assignees
Labels
in: core Issues in core support type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Hans Desmet opened DATAJPA-612 and commented

In the following interface, i try to apply @EntityGraph on the method findAll, which I inherit from JpaRepository:

public interface CustomerDAO extends JpaRepository<Customer, Long> {
	@Override
	@EntityGraph("Customer.withOffice")
	public List<Customer> findAll();	
}

When I start the application, I get a PropertyReferenceException:
No property findAll found for type Customer!

It would be convenient that Spring Data would apply the @EntityGraph instead of this exception, like Spring Data already applies @Query:

public interface CustomerDAO extends JpaRepository<Customer, Long> {
	@Override
	@Query("...")
	public List<Customer> findAll();	
}

Affects: 1.7 GA (Evans)

Issue Links:

  • DATAJPA-689 Allow @EntityGraph on findOne method of CrudRepository

Referenced from: pull request #109

Backported to: 1.7.1 (Evans SR1)

@spring-projects-issues
Copy link
Author

Thomas Darimont commented

Thanks for reporting that! :)

The problem is (IMHO) that org.springframework.data.jpa.repository.EntityGraph is marked as a @QueryAnnotation.
The purpose of @QueryAnnotation is to mark store specific @Query annotations like the ones in SD Mongo DB and SD JPA.

This leads to the fact that the overridden method gets enlisted in the "queryMethods" within org.springframework.data.repository.core.support.DefaultRepositoryInformation.getQueryMethods() since the check for a @QueryAnnotation in isQueryMethodCandidate returns true in this case.

This triggers the configured CreateIfNotFoundQueryLookupStrategy to try to lookup a named query named 'findAll' which doesn't exist...
If we'd simply remove the @QueryAnnotation from @EntityGraph then the correct method will be invoked, but the @EntityGraph configuration is not applied.

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Looks decent to me, minor comments in the PR

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Applied with a few minor changes:

  • Removed EntityGraphHints as is not used anymore
  • Slightly altered Jpa21Utils to avoid repeating the same code in SimpleJpaRepository
  • Added integration tests for EclipseLink and OpenJPA

@spring-projects-issues
Copy link
Author

Michael Simons commented

Hello,

i'd expect that to work also on findOne, but that's not the case as findOne is handle separately by SimpleJpaRepository. The entity manager should support EntityGraphs in the hints for find as well.

Any chance of getting this?

Kind Regards and thank for your work,
Michael

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Hm, findOne(…) is a bit tricky as we're currently not issuing a query for the execution but rather use special EntityManager APIs for that (i.e. em.find(…)). Michael Simons - would you mind to create a separate ticket for that?

@spring-projects-issues
Copy link
Author

Michael Simons commented

Not at all…

@spring-projects-issues
Copy link
Author

Thomas Darimont commented

I created DATAJPA-689 to track this - I already have a fix for that

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 type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants