-->
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.  [ 6 posts ] 
Author Message
 Post subject: Creating subcriteria on inheritors property
PostPosted: Wed Apr 04, 2007 3:45 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
If I have base class and 2 classes that inherit form that, then how to write a query on property which is defined differently in both inheritors?

Example :

class vehicle
{

}


class Bus : vehicle
{
public BusType busType;
}

class Car : vehicle
{
public int NumberOfWheels;
}

class BusType
{
public int NumberOfWheels;
}


Now, if I want to create subquery to find vehicles by number of wheels, how would it be ?
I never know if I have Bus or Car thats why I have mapped base class(vehicle).

NB! I am using Criteria API to create queries.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 4:26 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
More basic, how to create subcriteria on mapped class inheritors property?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:34 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Why can;t you pull the NumberOfWheels property up to the Vehicle superclass? Then you can just .Add(Expression.Eq("NumberOfWheels",2)) for a DetachedCriteria.For(typeof(Vehicle)) ?
If you want to restrict it to either Bus or Car, you'd simply make the DetachedCriteria.For(typeof(Bus)).

Mike

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 6:54 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
Unfortunately this is not solution for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 7:24 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
No idea, anybody ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 12:17 pm 
Newbie

Joined: Thu Apr 12, 2007 7:46 am
Posts: 3
Location: Switzerland
daffest wrote:
No idea, anybody ?


You could use a CreateSQLQuery for that

"
SELECT Id FROM Bus JOIN BusType ON BusType.busId = Bus.busTypeId WHERE NumberOfWheels = 2

UNION

SELECT Id FROM Car WHERE NumberOfWheels = 2
"

Henrique

ps: I hope it's not too late


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