Spring Data Jpa中的子查询 [英] Sub-Query in Spring Data Jpa

查看:135
本文介绍了Spring Data Jpa中的子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jpql中有这样的查询

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

但无法正常工作,我知道jpa 2支持select中的子查询,但找不到任何关于如何使用它的提示

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

推荐答案

摘自JPA 2.2规范,第4.6.16段:

Quote from the JPA 2.2 specification, paragraph 4.6.16:

子查询可以在WHERE或HAVING子句中使用.[66]

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

[66]在此版本中,子查询仅限于WHERE和HAVING子句.在本规范的更高版本中,将考虑对FROM子句中的子查询的支持.

[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.

这篇关于Spring Data Jpa中的子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆