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 bug with not ( ? = some elements(x) )
PostPosted: Wed Feb 04, 2009 6:33 pm 
Newbie

Joined: Wed Feb 04, 2009 5:53 pm
Posts: 1
Location: Chicago
Hibernate version: 3.3.1.GA

Name and version of the database you are using: MySQL 5

Data model:
LimbedPet extends Pet.
Pet has property "String name".
LimbedPet has additional property "List<String> limbs" which is mapped as an indexed list of values.

It seems that the HQL:
Code:
select pet.name from LimbedPet pet where not ( :limb = some elements(pet.limbs) )


is incorrectly translated to the SQL:
Code:
select limbedpet0_.name as col_0_0_
from Pet limbedpet0_
where limbedpet0_.limbed=1 and ?<>some
   (select limbs1_.element from Pet_limbs limbs1_ where limbedpet0_.id=limbs1_.Pet_id)


when it should be:
Code:
select limbedpet0_.name as col_0_0_
from Pet limbedpet0_
where limbedpet0_.limbed=1 and not ( ?=some
   (select limbs1_.element from Pet_limbs limbs1_ where limbedpet0_.id=limbs1_.Pet_id) )


Apparently the the query processor is trying to simplify "not ? = some ..." to "? <> some ...". Unfortunately these are not equivalent.

Say I have this data:
LimbedPet { name: "Ralph the dog", limbs: ['left front leg', 'right front leg', 'left hind leg', 'right hind leg'] }
LimbedPet { name: "Joe the ant", limbs: ['left front leg', 'right front leg', 'left hind leg', 'right hind leg', 'left middle leg', 'right middle leg'] }

The intent of the HQL query is to give me all limbed pets where none of the pet's legs is called X (?). In other words: it is not true that some of the pet's legs are called X (?)

If X is "right middle leg", this should give us ["Ralph the dog"].

Instead Hibernate is attempting to simplify the expression to say all limbed pets where some of the pet's legs are not called X(?)

With the same value for X, this gives us ["Ralph the dog", "Joe the ant"].


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.