-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL->SQL Optimization Bug with exists() clause
PostPosted: Wed Oct 10, 2007 7:05 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
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_)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.