I would like to know if it is possible to have subquery in a @Query annotation (org.springframework.data.jpa.repository.Query;)
I am getting a QuerySyntaxException o
I did get expected results in Spring-data jpa with
public final static String FIND_BY_ID_STATE = "SELECT a FROM Table1 a RIGHT JOIN a.table2Obj b " +
"WHERE b.column = :id" +
"AND a.id NOT IN (SELECT c.columnFromA from a.table3Obj c where state = :state)";
@Query(FIND_BY_ID_STATE)
public List findXXXXXXXX(@Param("id") Long id, @Param("state") Long state);
where
Table2Obj & Table3Obj are the mapping of the relationship between entities Table1 and Table2, Table3 respectively.
defined Like below.
@OneToMany(mappedBy = "xxx", fetch = FetchType.LAZY)
private Set table2Obj = new HashSet<>();