Hi everyone!
I have a problem with a query (via Criteria) on an abstract class, Hibernate seems to ignore all but one subclass on the where clause, so I was wondering if I was doing something wrong..
Hibernate version: 3.2.0.ga
Name and version of the database you are using: MySQL 5.0.27
The class structure is:
Code:
abstract class Movimento
joined-subclass Svalorizzazione
joined-subclass Perdita
joined-subclass Bolla
joined-subclass BollaScontrino
So Svalorizzazione, Perdita and Bolla extend Movimento, while BollaScontrino extends Bolla.
Svalorizzazione, Perdita and Bolla have the String property "numeroDocumento" (I can't put it directly inside Movimento for various "business" reasons.)
I need to get all the Movimento's with property "numeroDocumento" greater than, say, "1", so my Criteria goes like
Code:
Criteria c = s.createCriteria(Movimento.class);
c.add(Restrictions.gt("numeroDocumento", "1"));
List l = c.list();
The resulting query overlooks Bolla and Perdita in the where clause though:
Code:
select this_.id as id88_0_, ..., this_1_.numerodocumento as numerodo2_89_0_, this_2_.numerodocumento as numerodo2_90_0_, ..., this_4_.numerodocumento as numerodo2_92_0_, ...,
case when this_3_.id is not null then 3 when this_1_.id is not null then 1 when this_2_.id is not null then 2 when this_4_.id is not null then 4 when this_.id is not null then 0 end as clazz_0_
from
movimento this_ left outer join svalorizzazione this_1_ on this_.id=this_1_.id left outer join bolla this_2_ on this_.id=this_2_.id left outer join bollascontrino this_3_ on this_.id=this_3_.id left outer join perdita this_4_ on this_.id=this_4_.id
where
this_1_.numerodocumento>'1'
I think it should be something like
Code:
...
where
this_1_.numerodocumento>'1' or this_2_.numerodocumento>'1' or this_3_.numerodocumento>'1'
Am I missing something? Many thanks for your attention!