Hi,
I've an abstract class Content, which has a few subclasses extending from it: Video, Photo and Collection.
Using the criteria API I found out how to query all Content instances (doesn't matter if it's a Video, Photo or Collection):
Code:
Criteria crit = this.getSession().createCriteria(Content.class);
I also found out how to query for a specific content type, like querying only for Videos:
Code:
Criteria crit = this.getSession().createCriteria(Video.class);
Now what I did not find out is,
how can I query for Videos AND Photos, so the Collection instances are filtered out?
Do I need an extra distinction column for that in my content table or is there an easier way to do so?Thank you in advance
Humppa
Here is what I'm using:
Hibernate 3.4.0 GA
PostgreSQL 8.4.0
And the shortened mapping for the Content class:
Code:
<class name="content.Content" table="content" lazy="true">
<cache usage="read-write"/>
<id name="contentid" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">content_contentid_seq</param>
</generator>
</id>
<property name="views" not-null="true" />
<property name="dateadded" not-null="true" />
...
<joined-subclass name="content.video.Video"
table="video">
<key column="contentid" foreign-key="true" not-null="true"
unique="true">
</key>
<property name="videoid" unique-key="true" not-null="true"
insert="false" update="false">
</property>
<property name="url" not-null="true" />
...
</joined-subclass>
<joined-subclass name="content.photo.Photo"
table="photo">
<key column="contentid" foreign-key="true" not-null="true"
unique="true">
</key>
<property name="photoid" unique-key="true" not-null="true"
insert="false" update="false">
</property>
<property name="recorddate" />
...
</joined-subclass>
<joined-subclass name="content.collection.Collection"
table="collection">
<key column="contentid" foreign-key="true" not-null="true"
unique="true">
</key>
<property name="collectionid" unique-key="true" not-null="true"
insert="false" update="false">
</property>
<property name="publicCollection" column="public"/>
...
</joined-subclass>
</class>