-->
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 chains with joined-subclass
PostPosted: Thu Sep 30, 2004 1:13 pm 
Newbie

Joined: Thu Jun 03, 2004 10:29 am
Posts: 13
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


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.