-->
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: criteria API query, filter multiple joined subclasses
PostPosted: Fri Apr 30, 2010 8:21 am 
Beginner
Beginner

Joined: Tue Sep 08, 2009 9:49 am
Posts: 23
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>


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.