-->
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: How can I get a Criteria for multiple classes?
PostPosted: Thu May 21, 2009 2:40 pm 
Newbie

Joined: Thu May 21, 2009 2:35 pm
Posts: 4
Hello, I need some help.
I have classes A, B, C, D.
B, C and D extend A.
And I want to create a Criteria that would get me all the instances of B and C, but not D. How can I do that?
Thanks in advance!


Top
 Profile  
 
 Post subject: Re: How can I get a Criteria for multiple classes?
PostPosted: Sat May 23, 2009 8:23 pm 
Newbie

Joined: Tue Aug 07, 2007 12:46 pm
Posts: 4
Maybe you can define B and C to implement a common interface, while D would not implement this interface. Then you could build the criteria object for this new interface and get what you want. If you cannot modify B and/or C then you could build a criteria for A and add Restrictions.or(Restrictions.eq("class", "DISCRIMINATOR_VALUE_FOR_B"), Restrictions.eq("class", "DISCRIMINATOR_VALUE_FOR_C")) - this will work if both B and C are mapped to the same table and use a discriminator column. If you use any other inheritance mapping then you should run two different criteria queries and merge the resulting collections on your own. This will be as efficient as anything Hibernate could do for you, since these mapping strategies will require at least one query per inherance branch anyway.


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.