-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query for Multiple Subclass in Table Per hierarchy stratergy
PostPosted: Thu Mar 27, 2008 8:53 am 
Newbie

Joined: Fri Jun 10, 2005 9:32 am
Posts: 5
Hibernate version:3.2.5

All,

Need help in writing Criteria queries for Table Per Hierarchy Stratergy

Class & subclasses I have
Class : 'Vehicle' (discriminiator : V)
Subclass: 'LM Vehicle' (discriminiator : LMV)
Subclass: 'HM Vehicle' (discriminiator : HMV)
Subclass: 'HT Vehicle' (discriminiator : HTV)

Vehicle has an attribute 'power'.

If I want to query for all vehicle which has a power > 100bhp, my query would be
Criteria criteria = session.createCriteria(Vehicle.class);
criteria.addCriterion(Restrictions.gt("power", 100));
criteria.list();

<b>Now my question</b>
How do I query for only for LM Vehicle or HM Vehicles that has a power > 100bhp in one query?.
Criteria criteria = session.createCriteria(Vehicle.class);
//What to include in criteria, such that i can query on different vehicle types?.
criteria.addCriterion(Restrictions.gt("power", 100));
criteria.list();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 7:41 am 
Newbie

Joined: Fri Jun 10, 2005 9:32 am
Posts: 5
Any suggestions/tips, No one has faced this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 4:27 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
Quote:
//What to include in criteria, such that i can query on different vehicle types?.


you have to do query on the name of discriminator-column e.g. in your case discriminator column is "Vehicle_Type", then you will write HQL as follows

"from Vehicle where Vehicle_Type = HT"

for more details study the following blog. I m sure it will be helpful to you:

http://javainnovations.blogspot.com/2008/07/inheritance-strategy-class-per.html

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 10:11 am 
Newbie

Joined: Fri Jun 10, 2005 9:32 am
Posts: 5
Hi Amer,

Thanks for the reply, I'm looking at using Criteria API and not HQL for the query.


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