spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

Add support for combining @EntityGraph and Specification<T> [DATAJPA-1824]

Open spring-projects-issues opened this issue 4 years ago • 5 comments

Ruslan Stelmachenko opened DATAJPA-1824 and commented

Currently you can extend JpaSpecificationExecutor and use it's methods that support Specification<T> argument.

You can also create custom methods in repository interface with @EntityGraph annotation to control fetching of entity attributes.

But what is missing is the ability to combine Specification<T> argument and @EntityGraph annotation in custom methods. To make it work spring-data-jpa should support custom methods with Specification<T> argument (in addition to methods already present in JpaSpecificationExecutor).

The reason why this is important: Specification<T> defines the "where" (conditions) part of a query, while @EntityGraph defines the "select" (what fields to fetch) part of a query. So they are 2 independent things which can work together complementing each other.

The same is actually true for Projections. They define "what fields to fetch", but usually it's not enough because service layer must also pass a predicate to instruct repository layer on "what conditions to use"


Affects: 2.4.1 (2020.0.1)

spring-projects-issues avatar Nov 19 '20 13:11 spring-projects-issues

Is this new feature still in the process?

tinystorm avatar Nov 22 '22 05:11 tinystorm

Is this new feature still in the process?

tinystorm avatar Nov 22 '22 05:11 tinystorm

@TinyStorm for your information a library https://github.com/Cosium/spring-data-jpa-entity-graph allow you to combine the two. But I reckon that it would be great if it was vanilla.

kowlown avatar Jan 19 '23 17:01 kowlown

Hows the progress in this feature? Currently its the most upvoted issue

ly000 avatar Dec 19 '23 10:12 ly000