pramoth / specification-with-projection

Support projections with JpaSpecificationExecutor.findAll(Specification,Pageable) for Spring Data JPA
MIT License
164 stars 56 forks source link

Add the possibility to define de EntityGraph for the projection #21

Closed thesivis closed 3 years ago

thesivis commented 3 years ago

This annotation serves to determine if the projection should load the child property when you use distinct in a query

EntityParent { String name; EntityChild child; }

EntityChild { String name; }

When you create the query without the EntityGraph you get:

Select distinct p From EntityParent p inner join EntityChild c order by c.name

You get error because EntityChild was not returned, you need to load EntityChild

With annotation:

@LoadEntityGraph(paths="child") interface ProjectEntityParent{ EntityChildInfo getEntityChild();

interface EntityChildInfo { String name; } }

You get query

Select distinct p, c From EntityParent p inner join EntityChild c order by c.name

So you can define de EntityGraph per projection and not in Entity