Hibernate version: 2.1.6
I have a situation where I have 3 classes in an inheritance chain. I have been using a table-per-subclass strategy for the rest of my application.
In this case, I have to declare the base class with it's table and then map a joined-subclass of the last child with a second table. What I'd like to do is map each child to it's own table
This is the working mapping document
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.sebring">
<class name="User" table="USER_LOGIN">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">USER_LOGIN_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="timestamp" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="timestamp" column="CREATE_DATE" not-null="true"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<property name="name" type="string" column="NAME" not-null="true"/>
<property name="password" type="string" column="PASSWORD" not-null="true"/>
<property name="active" type="boolean" column="ACTIVE" not-null="true"/>
<many-to-one name="person" column="PERSON_ID" cascade="save-update"/>
<many-to-one name="region" column="REGION_ID"/>
<property name="admin" type="true_false" column="IS_ADMIN"/>
<bag name="creditCards" table="USER_CREDIT_CARD_LINK" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.sebring.CreditCard" column="CREDIT_CARD_ID"/>
</bag>
<joined-subclass name="com.sobetech.bristol.BristolUser" table="BRISTOL_USER">
<key column="USER_ID"/>
<property name="lookingForBand" type="true_false" column="LOOKING_FOR_BAND"/>
<property name="displayLookingForBand" type="true_false" column="DISPLAY_LOOKING_FOR_BAND"/>
<property name="searchable" type="true_false" column="SEARCHABLE" not-null="true"/>
<bag name="playlists" table="USER_PLAYLIST_LINK" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.bristol.Playlist" column="PLAYLIST_ID"/>
</bag>
<bag name="friends" table="USER_FRIENDS" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.bristol.BristolUser" column="FRIEND_ID"/>
</bag>
</joined-subclass>
</class>
</hibernate-mapping>
This is the way I'd dream it up. I know this is not a working mapping, but I think it help illustrates my desire
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.sebring">
<class name="User" table="USER_LOGIN">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">USER_LOGIN_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="timestamp" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="timestamp" column="CREATE_DATE" not-null="true"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<property name="name" type="string" column="NAME" not-null="true"/>
<property name="password" type="string" column="PASSWORD" not-null="true"/>
<property name="active" type="boolean" column="ACTIVE" not-null="true"/>
<many-to-one name="person" column="PERSON_ID" cascade="save-update"/>
<many-to-one name="region" column="REGION_ID"/>
<property name="admin" type="true_false" column="IS_ADMIN"/>
<bag name="creditCards" table="USER_CREDIT_CARD_LINK" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.sebring.CreditCard" column="CREDIT_CARD_ID"/>
</bag>
<joined-subclass name="com.sobetech.imola.ImolaUser" table="IMOLA_USER">
<key column="USER_ID"/>
<property name="searchable" type="true_false" column="SEARCHABLE" not-null="true"/>
<joined-subclass name="com.sobetech.bristol.BristolUser" table="BRISTOL_USER">
<key column="USER_ID"/>
<property name="lookingForBand" type="true_false" column="LOOKING_FOR_BAND"/>
<property name="displayLookingForBand" type="true_false" column="DISPLAY_LOOKING_FOR_BAND"/>
<bag name="playlists" table="USER_PLAYLIST_LINK" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.bristol.Playlist" column="PLAYLIST_ID"/>
</bag>
<bag name="friends" table="USER_FRIENDS" lazy="false">
<key column="USER_ID"/>
<many-to-many class="com.sobetech.bristol.BristolUser" column="FRIEND_ID"/>
</bag>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
Any ideas. Will this become possible in version 3.x?
Thanks
|