EDIT: Specifically talking about querying against no table. Yes I can use exists, but I’d have to do
select case when exists (blah) then 1 else 0 end as conditionTrue
from ARealTableReturningMultipleRows
In T-SQL I can do:
select case when exists(blah) then 1 else 0 end as conditionTrue
In Oracle I can do:
select case when exists(blah) then 1 else 0 end as conditionTrue from DUAL
How can I achieve the same thing in HQL?
select count() seems like the second-best alternative, but I don’t want to have to process every row in the table if I don’t need to.
Short answer: I believe it’s NOT possible.
My reasoning:
According to Where can I find a list of all HQL keywords? Hibernate project doesn’t publish HQL grammar on their website, it’s available in the Hibernate full distribution as a
.gANTLR file though.I don’t have much experience with
.gfiles from ANTLR, but you can find this in the file (hibernate-distribution-3.6.1.Final/project/core/src/main/antlr/hql.g):which clearly states there are some HQL queries having no
FROMclause, but that’s acceptable if that’s a filter query. Now again, I am not an expert in HQL/Hibernate, but I believe a filter query is not a full query but something you define usingsession.createFilter(see How do I turn item ordering HQL into a filter query?), so that makes me think there’s no way to omit theFROMclause.