-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL inequality operator on composite-id generate wrong SQL
PostPosted: Mon Jan 24, 2011 7:02 am 
Newbie

Joined: Thu Apr 03, 2008 3:42 am
Posts: 2
I can't find any thread/issue on this looking in the forum or jira.

inequality operator used on a composite-id generate the corresponding sql using AND instead of OR (behaviour tested using hibernate 3.2.7 DB H2/Oracle)

mapping snippet:

Code:
   <class name="d.p.entityIDMUnit.lim.bl.pom.impl.PPKone" table="PPKone">
      <composite-id>
         <key-property name="i" type="IntegerType">
            <column name="c_i_5b145" precision="19" scale="0"/>
         </key-property>
         <key-property name="j" type="IntegerType">
            <column name="c_j_4534d" precision="19" scale="0"/>
         </key-property>
      </composite-id>
               ...

sample HQL: from d.p.entityIDMUnit.lim.bl.pom.impl.PPKone p where (( ( p <> p ) or ( p.i = 1 ) ))

SQL:

Code:
select
ppkone0_.c_i_5b145 as c1_16_,
ppkone0_.c_j_4534d as c2_16_,
ppkone0_.version$ as version3_16_
from
   PPKone ppkone0_
where
   ppkone0_.c_i_5b145<>ppkone0_.c_i_5b145
   and ppkone0_.c_j_4534d<>ppkone0_.c_j_4534d
   or ppkone0_.c_i_5b145=1


as you can see parenthesis disappeared and the SQL production for the pk is checking the equality of the whole pk when the condition should be true if just one field of the two is different, that's it the correct production should be:
Code:
ppkone0_.c_i_5b145<>ppkone0_.c_i_5b145
OR ppkone0_.c_j_4534d<>ppkone0_.c_j_4534d

and the parenthesis become mandatory in order to avoid wrong results.

Explicit use of the id ( p.id <> p.id ) produce the same result.

I can't believe there's no other thread/issue on that so point me to the thread/issue if you know or tell me what is wrong in the code above :)

Thanks Paizo


Last edited by Paizo on Tue Feb 01, 2011 4:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: HQL inequality operator on composite-id generate wrong SQL
PostPosted: Tue Jan 25, 2011 7:10 am 
Newbie

Joined: Thu Apr 03, 2008 3:42 am
Posts: 2
The same issue occur using a component instead of the composite-id, Hibernate keep checking that ALL fields are differents for both equals and not equals, again the latter need the tuple to use OR instead of AND.


Top
 Profile  
 
 Post subject: Re: HQL inequality operator on composite-id generate wrong SQL
PostPosted: Tue Jan 25, 2011 7:45 am 
Newbie

Joined: Fri Jan 18, 2008 5:28 am
Posts: 3
Location: Italy
i have the same issue...no aswer by H-team?


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