is there a good reference for using OR clauses in HQL? i seem to end up with cartesian products against my will. for instance, the following hql:
Code:
select count(*) from Library library where ( library.books.size > 0 or library.magazines.size > 0 )
generates the following SQL:
Code:
select count(*) as col_0_0_
from LIBRARY library0_, BOOK books1_, MAGAZINE magazines2_
where (
(select count(books1_.LIBRARY_GUID)
from BOOK books1_
where library0_.LIBRARY_GUID=books1_.LIBRARY_GUID) > 0
or
(select count(magazines2_.LIBRARY_GUID) from MAGAZINE magazines2_
where library0_.LIBRARY_GUID=magazines2_.LIBRARY_GUID)>0
and library0_.LIBRARY_GUID=books1_.LIBRARY_GUID
and library0_.LIBRARY_GUID=magazines2_.LIBRARY_GUID)
instead of the correct:
Code:
select count(*) as col_0_0_
from LIBRARY library0_, BOOK books1_, MAGAZINE magazines2_
where (
(select count(books1_.LIBRARY_GUID)
from BOOK books1_
where library0_.LIBRARY_GUID=books1_.LIBRARY_GUID) > 0
or
(select count(magazines2_.LIBRARY_GUID) from MAGAZINE magazines2_
where library0_.LIBRARY_GUID=magazines2_.LIBRARY_GUID)>0)
and
library0_.LIBRARY_GUID=books1_.LIBRARY_GUID
and library0_.LIBRARY_GUID=magazines2_.LIBRARY_GUID
in other words it generates
(A or B and C and D) instead of
(A or B) and C and D
i'd be grateful for pointers on how to do this correctly in HQL. i am building a query based on several user inputs, and three of the criteria can follow this "or" strategy (so doing some sort of union as a hack is too messy)
john