'Spring Data JPA: Using multiple entity in SpEL notation?
I used SpEL for generic entity name in my Spring Data JPA repositories. This time, I need to join 2 tables via JPQL and for this purpose, I am wondering if I can use multiple entity by passing to the repository and then using it in my query as SpEL 's ${#entityName}. So, is it possible?
DiningRepository:
@Query("select d as dining, dg as diningGroup, s as site " +
"from Dining d " +
" join DiningGroup dg on d.groupUuid = dg.uuid " +
" join Site s on dg.siteUuid = s.uuid " +
"where d.uuid = :uuid")
Optional<GroupAndSiteProjection> findByUuid(@Param("uuid") UUID uuid);
Here is projection where I collect Dining, DiningGroup and ``Site` result:
public interface GroupAndSiteProjection {
Dining getDining();
DiningGroup getDiningGroup();
Site getSite();
}
The method is in DiningRepository and ${#entityName} gets Dining entity. But I want to use also DiningGroup by passing it to the repository as generic e.g. DiningRepository<Dining, DiningGroup>... Is it possible?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
