-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL query using a property of a subclass
PostPosted: Tue Feb 15, 2005 7:11 am 
Newbie

Joined: Tue Feb 15, 2005 6:59 am
Posts: 1
Location: UK
Hibernate: 2.1.4

Database: PostgreSQL 7.4

I've had a good search round the forums, FAQs and Docs and can't find an answer to my question. If I've missed something let me know.

I'm trying to construct an HQL query from the following objects
Code:
       Mention --> Article --> Source
                      /\         /\
                    Cutting --> Publication --> PublicationType

A mention is associated with an article and and an article is published in a source.
I then have a number of sub-classes of article and source that extend these classes for the particular medium (newspaper, website, newswire etc).

I am interested in returning all the Mentions from Cuttings in Publications with a particular publication type.

I started with this:

Code:
select mention from Mention join mention.article as article join article.source as source


but cannot see how to "cast" the article and source into the more specific cutting and publication in order to be able to add the where clause:

Code:
select mention from Mention join mention.article as article join article.source as source where source.publicationType = 'National'


I've looked at using the HQL property .class to return only articles that are Cuttings but I don't seem to be able to further filter the objects returned using a property only present in the Cutting subclass.

The best I've managed so far is:

Code:
select mention from Mention join mention.article as article, Cutting as cutting join cutting.publication as publication where cutting.articleID = article.articleID and publication.publicationType = 'National'


Is this the only way I can use the properties of a subclass or is there a better way to write the HQL statement?

The subclasses are mapped as joined-subclasses and the database has one table per class.

Thanks for any pointers or solutions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.