-->
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: Inheritance - detecting whether super class is subclassed
PostPosted: Tue Jun 12, 2007 10:50 am 
Newbie

Joined: Wed Feb 14, 2007 11:18 am
Posts: 10
I am using a table-per-subclass paradigm. The superclass is Person, which is extended by several other entities, eg., Member, Donor, Staff, etc. Here is the mapping for Person (which includes only the subclass mapping for Member):


Code:
<hibernate-mapping>
   <class name="Person" table="person"
      catalog="mlac">
      <id name="personId" type="java.lang.Integer">
         <column name="person_id" />
         <generator class="identity"></generator>
      </id>
       <property name="lastName" type="java.lang.String">
            <column name="last_name" length="45" not-null="true" />
        </property>
        <property name="firstName" type="java.lang.String">
            <column name="first_name" length="45" />
        </property>
       
..........

      <set name="addresses" table="person_addr" cascade="save-update" lazy="false">
         <key>
            <column name="person_id" />
         </key>
         <many-to-many class="com.ravencsi.hibernate.Address" column="address_id" unique="false"/>
      </set>
      
      <joined-subclass name="com.ravencsi.hibernate.Member" table="member">
         <key column="person_id" />
         <property name="createYear" type="java.lang.Integer">
            <column name="create_year" />
         </property>
         <property name="expireDate" type="java.util.Date">
            <column name="expire_date" length="0" />
         </property>
         <property name="renewDate" type="java.util.Date">
            <column name="renew_date" length="0" />
         </property>
         <property name="cardPrinted" type="java.util.Date">
            <column name="card_printed" length="0" />
         </property>
         <property name="cost" type="java.lang.Double">
            <column name="cost" precision="22" scale="0" />
         </property>
         <property name="exception" type="java.lang.Double">
            <column name="exception" precision="22" scale="0" />
         </property>
      </joined-subclass>
   </class>
</hibernate-mapping>


When I do a query for Person (usually a simple Criteria query), Hibernate will do an outer join to pick up all the Member records (a behavior that other users have complained about). I want to be able to detect when a Person is also a Member, Donor, etc. in the same fetch, and park that result in a property in Person. I think I can leverage the hql that is generated and imbed a test of the subclass in the *.hbm.xml map file, but I am not sure of the syntax.

Does anyone know whether this can be done and how?

_________________
Tom McC.
"better to journey than to arrive"


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.