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

前端 未结 3 1767
庸人自扰
庸人自扰 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:33

    No, it is not possible to have subquery in the select clause in JPQL query.

    JPQL supports subqueries in WHERE and HAVING clauses. It can be (at least) part of ANY, SOME, ALL, IN, EXIST expressions, and of course it can be used normal conditional expressions:

    SELECT a
    FROM A a
    WHERE a.val = (SELECT b.someval 
                   FROM B b 
                   WHERE b.someotherval=3)
    

提交回复
热议问题