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.