Hibernate version: 3.2.3 GA
Name and version of the database you are using: Oracle 10g
We think that we found a bug in the way that Hibernate transforms a HQL query into a SQL statement.
The problem occurs when it comes to the application of De Morgan's law:
Code:
not(A or B) -> not(A) and not(B)
or
not(A and B) -> not(A) or not(B)
Suppose the following trivial mapped object:
Code:
public class Semaphore {
private Long oid;
private String name;
}
...and the following HQL query:
Code:
from Semaphore s where not(s.name is null and s.oid is null)
Hibernate applies De Morgan's law and generates the following SQL query:
Code:
select semaphore0_.oid as oid52_, semaphore0_.name as name52_ from SEMAPHORES semaphore0_ where semaphore0_.name is not null or semaphore0_.oid is not null
That's correct behaviour. Hibernate inverses the two clauses and makes 'is not null' from 'is null'.
But when a clause contains the exists operator, Hibernate doesn't inverse it:
Code:
from Semaphore s where not(s.name is null and exists(select x.oid from Semaphore x))
Hibernate generates an incorrect SQL query, because the exists result isn't inversed:
Code:
select semaphore0_.oid as oid52_, semaphore0_.name as name52_ from SEMAPHORES semaphore0_ where semaphore0_.name is not null or exists (select semaphore1_.oid from SEMAPHORES semaphore1_)