-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bug at HQL to SQL mapping in createQuery?
PostPosted: Tue Nov 04, 2008 8:00 am 
Newbie

Joined: Tue Nov 04, 2008 7:40 am
Posts: 2
hi,

I have had weird problem creating a query with HQL.


DEBUG - HQL: select myThing from MyClass where .. <clauses that work> AND ( ( foo1 <> (:value1) AND foo1 < (:value2) ) OR ( foo1 = (:value1) AND foo2 < (:value3) ) )

maps to:

DEBUG - SQL: select myThing as col_0_0_ from myclass_table where .. <clauses that work> and (foo1<>? and foo1<? or foo1=? and foo2<?)

So there is couple () missing and whole query loses it's meaning.

Same kind of thing works corretly with Criteria if I create two 'AND' clauses as Criterion and put them to criteria with Restrictions.or(criterionA, criterionB).

So my question is: Is this really a bug or am I doing something wrong? Do I have to add something to query so it maps HQL to SQL way I want it to map with those () marks on right place.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2008 8:38 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The translation seems correct. Comparisons are evaluated before AND:s that are evaluated before OR:s so the parenthesis should not be needed.


Top
 Profile  
 
 Post subject: Re: Bug at HQL to SQL mapping in createQuery?
PostPosted: Tue Nov 04, 2008 9:04 am 
Newbie

Joined: Tue Nov 04, 2008 7:40 am
Posts: 2
Yes, comparsions are evaluated before. But OR is for those two different AND:s. Without parenthesis OR is only for foo1<(:value2) and foo1=(:value1) clauses which I do not intent. It gives whole different output with or without parenthesis.

If I get query from using criteria I get this:

DEBUG - select myThing as col_0_0_ from myclass_table where .. <clauses that work> and ((foo1<>? and foo1<?) or (foo1=? and foo2<?))

So parenthesis are on their place.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2008 9:16 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Without parenthesis OR is only for foo1<(:value2) and foo1=(:value1) clauses


If it is so, then your database is different from all other databases and programming languages I know of.

Code:
A and B or C and D


is equivalent to

Code:
(A and B) or (C and D)


not

Code:
A and (B or C) and D


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.