Spring 数据 Jpa 中的子查询

Sub-Query in Spring Data Jpa

我在 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

但不起作用,我知道 jpa 2 在 select 中支持子查询,但找不到任何关于如何使用它的参考

引自 JPA 2.2 规范第 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.