Hello Everybody!
I've been using Hibernate for a while now, but this is my first posting to this forum. Hiberante is great, thank you! :) Still, I have a problem.
I'm trying to execute an HQL query which has subqueries. The generated SQL seems to be wrong.
Hibernate version:
3.2.CR2,
3.1
Code between sessionFactory.openSession() and session.close():
String q =
"from table1 where
not(
exists( from table2 )
or
exists( from table3 )
)"
s.createQuery(q).list();
Name and version of the database you are using:
Postgresql 8.1
The generated SQL (show_sql=true):
Hibernate:
select model_user0_.id as id1_, ...
from table1 model_user0_
where
(exists (select model_user1_.id from table2 model_user1_))
and
(exists (select model_user2_.id from table3 model_user2_))
So. The point is that Hibarnate seems to translate the HQL condition:
not( exists(...) or exists(...) )
into SQL by something like
exists(...) and exists(...)
that is obviously not the same thing.
If the SQL was :
not( exists(...) ) and not( exists(...) )
than it would be correct, I guess, but this is not happening.
By the way, the query shown here is just a demonstration, it does not make any sense, but it should still work. My real query is much more compicated that this, I'm just trying to focus on the problem by removing the unneccessary parts.
What do you think? Is it really an existing problem in Hibarnate or I am doing something wrong? I also checked out the latest(?) code from svn, but it produced the same results.
Thank you,
Marton
|