-->
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.  [ 3 posts ] 
Author Message
 Post subject: List query of a particular subtype
PostPosted: Sat Jun 18, 2005 1:12 pm 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Hibernate version:
3.0.5
Mapping documents:
<class name="org.brs.ck.Status" table="status">
<id name="id" type="int">
<column name="id" length="11" not-null="true" unique="true" sql-type="int" />
<generator class="assigned" />
</id>

<discriminator column="type" type="string" />

<property name="userId" type="int">
<column name="user_id" length="11" not-null="true" sql-type="int" />
</property>
<property name="reoccuring" type="boolean" >
<column name="reoccuring" length="1" not-null="true" sql-type="tinyint" />
</property>
<property name="reason" type="string" >
<column name="reason" length="64" not-null="false" sql-type="varchar" />
</property>
<property name="startDate" type="java.util.Date">
<column name="startDate" length="10" not-null="true" sql-type="date" />
</property>
<property name="endDate" type="java.util.Date">
<column name="endDate" length="10" not-null="false" sql-type="date" />
</property>

<subclass name="org.brs.ck.util.SimpleStatus" discriminator-value="SS" />
<subclass name="org.brs.ck.util.RangeStatus" discriminator-value="RS" />
<subclass name="org.brs.ck.util.ReoccuringRangeStatus" discriminator-value="3" />

</class>
Full stack trace of any exception that occurs:

Name and version of the database you are using:
Mysql 4.1.something

Question is...

I want to run a list query against a particular sub-type. I want to find all items of a particular subtype who's endDate is older than now.

The basic list query part is simple enough but ideally, I'd like to return a list of only the RangeStatus objects. Currently I'm just using "instance of" during iteration to find the right objects in the list, but I could make the query more efficient by returning only the RangeObjects as well as avoiding the reflection.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 1:52 pm 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Found my own answer through testing.

just submit the query "from RangeStats as... etc."

Worked like a charm. Hibernate rocks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 2:54 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
Another solution is to use the special property 'class':

Code:
select * from Status s where s.class='RangeStatus'


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.