Sub-Query in Spring Data Jpa

谁说胖子不能爱 提交于 2020-01-06 01:30:32

问题


I have query like this in jpql

select new com.example.CustomGroup(m.id, m.title, (select count(w.id) from MessageGroup x join x.messages w where w.readers.id <> ?1) ) 
from MessageGroup m join m.members u where u.id = ?1

but not work, i know jpa 2 support sub query in select but cant find any refrence to how use it


回答1:


Quote from the JPA 2.2 specification, paragraph 4.6.16:

Subqueries may be used in the WHERE or HAVING clause.[66]

[66] Subqueries are restricted to the WHERE and HAVING clauses in this release. Support for subqueries in the FROM clause will be considered in a later release of this specification.



来源:https://stackoverflow.com/questions/52488603/sub-query-in-spring-data-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!