-->
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: Easy Newbie XML Mapping Question: Inheritance
PostPosted: Sun Jul 31, 2005 1:28 pm 
Beginner
Beginner

Joined: Sun Jul 31, 2005 1:23 pm
Posts: 35
Hibernate 3.0.5
MySQL 4.1.13
Windows XP/SP2

How do define the XML mapping information for this relational table layout. I don't care if the foreign key or cascading properties don't come out right; I just want to get the basic hierarchy working correctly.

Code:
-- This defines the ID space shared by different derived table types.
CREATE TABLE GenericObjects
(
   ID      INTEGER NOT NULL AUTO_INCREMENT,

   CONSTRAINT PK_GenericObjects PRIMARY KEY (ID)
);

-- There will be other similar tables dervied from GenericObjects.
CREATE TABLE DerivedObjects
(
   ID      INTEGER NOT NULL,

   OtherData   INTEGER NULL,

   PRIMARY KEY PK_DerivedObjects(ID),
   FOREIGN KEY (ID) REFERENCES GenericObjects (ID) ON DELETE CASCADE
);


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 31, 2005 1:47 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
see

http://www.hibernate.org/hib_docs/v3/re ... ersubclass


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 31, 2005 4:40 pm 
Beginner
Beginner

Joined: Sun Jul 31, 2005 1:23 pm
Posts: 35
anar wrote:
http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html#inheritance-tablepersubclass


Thank you! Problem sovled. For those that care:

In GenericObject.hbm.xml

Code:
<hibernate-mapping>
    <class name="GenericObject" table="GenericObjects">
        <id name="id" column="ID">
            <generator class="native"/>
        </id>
    </class>
</hibernate-mapping>


In DerivedObject.hbm.xml

Code:
<hibernate-mapping>
    <joined-subclass
             name="DerivedObject"
             table="DerivedObjects"
             extends="GenericObject">
        <key column="ID"/>

        <property name="otherData" column="OtherData"/>
    </joined-subclass>
</hibernate-mapping>


Wow, this Hibernate library is really great thus far!


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.