-->
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: Polymorphic queries
PostPosted: Sun Oct 02, 2005 11:45 am 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
I have a class which has a many-to-one polymorphic association e.g. we have OrderItem which links to Product which has MusicProduct and FilmProduct as subclasses.

Can I issue an HQL query that returns OrderItems that refer to only MusicProduct.

Had a look on the Hibernate forum, but only found unanswered questions.

TIA

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 2:39 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
hmm, something like "from OrderItem oi where oi.Product.class = Fully.Qualified.MusicProduct" maybe?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 5:08 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
Get's me half way there as I also need to restrict on properties that only exist on the subclass.

Think I've got it, but I don't know how general this is; this should retreive and order that contains a MusicalProduct...

select item.Order
from OrderItem item, MusicProduct mp
where item.Product = mp
and mp.IsrcCode = 'Fred'

You have to introduce the subclass explicitly as there doesn't seem to be a way of casting it to the subclass in HQL.

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 31, 2005 5:26 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Actually, I'm interested to know whether anyone knows more about this - is there a way to doing casting to a subclass in a query so that a property from a derived class can be included? Or is it absolutely required to do it the way paulh has described?


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.