-->
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.  [ 7 posts ] 
Author Message
 Post subject: SQL query produced from HQL
PostPosted: Thu Aug 18, 2005 12:40 pm 
Newbie

Joined: Thu Jun 24, 2004 4:06 am
Posts: 9
Hibernate version: 3.0.5

My HQL query:

from com.reservit.plannit.data.bo.inventory.EngCatInventoryBO as EngCatInventory where NOT ( ( EngCatInventory.fromdate > ? ) OR ( EngCatInventory.todate < ? ) ) AND ( ( EngCatInventory.roomcategory = ? ) )

is translated into SQL code:

select engcatinve0_.id as id, engcatinve0_.partid as partid21_, engcatinve0_.fromdate as fromdate21_, engcatinve0_.todate as todate21_, engcatinve0_.roomcategory as roomcate5_21_, engcatinve0_.engallotment as engallot6_21_ from engcatinventory engcatinve0_ where engcatinve0_.fromdate<=? and engcatinve0_.todate>=? and engcatinve0_.roomcategory=?

as you can see:
the NOT was dropped
the date compare are not correct (< substitute to <= and > to >=)

objets returns when this query is executed are of course not correct

What happens? is it a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:00 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Umm...what I can see from your HQL and the generated SQL output seems to be 100 per cent correct.

Code:
where NOT ( ( EngCatInventory.fromdate > ? ) OR ( EngCatInventory.todate < ? ) ) AND ( ( EngCatInventory.roomcategory = ? ) )


corresponds to

Code:
where engcatinve0_.fromdate<=? and engcatinve0_.todate>=? and engcatinve0_.roomcategory=?


Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject: Re: SQL query produced from HQL
PostPosted: Thu Aug 18, 2005 1:05 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
MARTINO wrote:
Hibernate version: 3.0.5

My HQL query:

from com.reservit.plannit.data.bo.inventory.EngCatInventoryBO as EngCatInventory where NOT ( ( EngCatInventory.fromdate > ? ) OR ( EngCatInventory.todate < ? ) ) AND ( ( EngCatInventory.roomcategory = ? ) )

is translated into SQL code:

select engcatinve0_.id as id, engcatinve0_.partid as partid21_, engcatinve0_.fromdate as fromdate21_, engcatinve0_.todate as todate21_, engcatinve0_.roomcategory as roomcate5_21_, engcatinve0_.engallotment as engallot6_21_ from engcatinventory engcatinve0_ where engcatinve0_.fromdate<=? and engcatinve0_.todate>=? and engcatinve0_.roomcategory=?

as you can see:
the NOT was dropped
the date compare are not correct (< substitute to <= and > to >=)

objets returns when this query is executed are of course not correct

What happens? is it a bug?


Why do you think that result are incorrect? Hibernate just simplified your condition to equivalent one.

Your condition:

not (x>? or y<?) and z=?


Hibernate:

x<=? and y>=? and z=?


On which data they are evaluated differently?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:08 pm 
Newbie

Joined: Thu Jun 24, 2004 4:06 am
Posts: 9
well i understand where is the problem
in fact this is not a OR but a XOR.
because begin date is always before end date
on my db, if i execute the SQL request, good results are returns
hibernate change my request using pure boolean algebric rules.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:18 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
So, you try to emulate XOR? Can you show example of your data and what select returns in both cases? This should be good test case for Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I seem to recall from high school that !(a&b) <=> !a|!b

;-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:31 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
MARTINO wrote:
well i understand where is the problem
in fact this is not a OR but a XOR.
because begin date is always before end date
on my db, if i execute the SQL request, good results are returns
hibernate change my request using pure boolean algebric rules.


Sorry, I still don't understand what should be wrong.
You wrote:

Quote:
the date compare are not correct (< substitute to <= and > to >=)

That's not true. Look at what you've written.

If you still think it's incorrect post your SQL statement which works on your database and the corresponding query in HQL you're using.

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


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

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.