Sql 如何选择HQL中是否存在行

Sql 如何选择HQL中是否存在行,sql,hibernate,hql,Sql,Hibernate,Hql,EDIT:专门讨论对no表的查询。是的,我可以用它,但我必须这么做 select case when exists (blah) then 1 else 0 end as conditionTrue from ARealTableReturningMultipleRows 在T-SQL中,我可以做到: select case when exists(blah) then 1 else 0 end as conditionTrue select case when exists(blah)

EDIT:专门讨论对no表的查询。是的,我可以用它,但我必须这么做

select case when exists (blah) then 1 else 0 end as conditionTrue
from ARealTableReturningMultipleRows

在T-SQL中,我可以做到:

select case when exists(blah) then 1 else 0 end as conditionTrue
select case when exists(blah) then 1 else 0 end as conditionTrue from DUAL
在Oracle中,我可以做到:

select case when exists(blah) then 1 else 0 end as conditionTrue
select case when exists(blah) then 1 else 0 end as conditionTrue from DUAL
如何在HQL中实现同样的功能


select count()似乎是第二个最佳选择,但如果不需要,我不想处理表中的每一行。

根据它,它们似乎同时支持大小写和exists语句。

简短回答:我相信这是不可能的。

我的理由是:

根据Hibernate项目并没有在他们的网站上发布HQL语法,它在Hibernate完整发行版中作为
.g
ANTLR文件提供

我对ANTLR中的
.g
文件没有太多经验,但您可以在文件(
hibernate-distribution-3.6.1.Final/project/core/src/main/ANTLR/hql.g
)中找到这一点:


这清楚地表明,有些HQL查询没有来自子句的
,但如果这是一个过滤器查询,那么这是可以接受的。再说一次,我不是HQL/Hibernate方面的专家,但我相信筛选查询不是完整查询,而是您使用
session.createFilter
(请参阅)定义的查询,因此我认为无法从
子句中省略

我使用带有一行的伪表,例如MyDual

    select case when exists(blah) then 1 else 0 end as conditionTrue from MyDual

看看这个问题:编辑这个问题以更好地反映我的意思。很抱歉把你弄糊涂了。啊,我明白了,看起来很像我很久以前问的一个没有答案的问题。如果你得到一个可行的方法,也许你会考虑把它添加到我的问题中。这是伟大的研究,非常感谢!我将把这个标记为目前公认的答案,希望有一天你的答案不再正确