SpringData : is it possible to have subqueries in the Query annotation?

前端 未结 3 1775
庸人自扰
庸人自扰 2020-12-06 11:48

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

3条回答
  •  生来不讨喜
    2020-12-06 12:40

    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<>();
    

提交回复
热议问题