在JPQL中可以选择EXISTS()吗? [英] Is Select EXISTS() possible in JPQL?

查看:745
本文介绍了在JPQL中可以选择EXISTS()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个查询,检查某些条件是否为真,并返回一个简单的布尔结果作为输出。让它有点棘手的是,其中一个条件是测试是否没有为一组标准返回结果。

I'm trying to run a query that checks if some conditions are true and returns a simple boolean result as output. What makes it slightly tricky is that one of the conditions is to test for whether no results are returned for a set of criteria.

我目前正在使用JPA-2.0 hibernate作为我的提供者,由MySQL支持。我已经得到了一个在MySQL中运行良好的示例查询,但是当试图让它在JPQL中运行时,它会失败。 MySQL查询看起来有点像这样:

I'm currently using JPA-2.0 with hibernate as my provider, backed by MySQL. I have gotten an example query working fine in MySQL, but when trying to get it running in JPQL it flops. The MySQL query looks a bit like this:

Select exists(Select statement with criteria) 
  or not exists(Select statement with criteria);

我也使用CASE获得相同的输出,但因为JPQL不支持该语句。

I also got the same output using CASE, but as JPQL doesn't support that statement.

无论如何,当我尝试在JPQL中使用类似的查询时,我得到错误:

Anyways, when I try to use a similar query in JPQL I get the error:


意外结束子树

"unexpected end of subtree"

根据我的理解,这意味着查询中缺少某些内容。有没有人知道如何解决它?

which from my understanding means that something is missing in the query. Does anyone have any idea how to fix it?

推荐答案

不,这是不可能的。

请参阅 JPQL来自oracle的BNF 文档。


simple_cond_expression :: = comparison_expression | between_expression | like_expression | in_expression | null_comparison_expression | empty_collection_comparison_expression | collection_member_expression | exists_expression

simple_cond_expression ::= comparison_expression | between_expression | like_expression | in_expression | null_comparison_expression | empty_collection_comparison_expression | collection_member_expression | exists_expression

exists_expression :: = [NOT] EXISTS(子查询)

exists_expression ::= [NOT] EXISTS(subquery)

这篇关于在JPQL中可以选择EXISTS()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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