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?