-->
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.  [ 2 posts ] 
Author Message
 Post subject: Query for subclass property sees just 1 subclass
PostPosted: Tue Sep 18, 2007 10:59 am 
Newbie

Joined: Fri Jan 12, 2007 12:25 pm
Posts: 6
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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 11:18 am 
Newbie

Joined: Fri Jan 12, 2007 12:25 pm
Posts: 6
Maybe it's because Hibernate gets confused by the fact that every subclass has a property with the same name, so it stops at the first one? Any ideas? ^^; Is this design Very Wrong?


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