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"].