-->
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: How to write mapping files for parent and child tables
PostPosted: Thu Oct 05, 2006 7:43 am 
Newbie

Joined: Mon Sep 18, 2006 9:46 am
Posts: 13
Hi,

I am new to hibernate. I am having parent table related with multiple child tables.

How can i write hbm.xml files for parent and child tables.

Help me..


Thanks
Ahamad


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 8:35 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Have a look at Chapters 6 and 7 of the documentation:

http://www.hibernate.org/hib_docs/v3/reference/en/html/

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 4:54 pm 
Newbie

Joined: Tue Sep 19, 2006 7:07 pm
Posts: 9
You can have more the one kind of inheritance.

If you have one table for each class, you will use inheritance of table for subclass. You should map only the superclass and the subclasses are mapped in the superclass map file.

<hibernate-mapping>
<class name="SuperClass" table="SuperClass">
<id name="ID_SUPERCLASS" type="Int">
<generator class="XXX"/>
</id>

<property name="XXX" type="int"/>

<joined-subclass name="SubClass1" table="SubClass1">
<key column="ID_SUBCLASS1"/>
<property name="XXX" type="int"/>
</joined-subclass>

<joined-subclass name="SubClass2" table="SubClass2">
<key column="ID_SUBCLASS2"/>
<property name="XXX" type="int"/>
</joined-subclass>
</class>
</hibernate-mapping>

If you have just one table for both superclass and subclasses, you will use inheritance of table for class hierarchy. In this case, your table need to have a column to indentify the subclasses called discriminator column.

<hibernate-mapping>
<class name="SuperClass" table="SuperClass">
<id name="ID_SUPERCLASS" type="Int">
<generator class="XXX"/>
</id>
<discriminator column="Class_Type" type="String"/>

<!--properties of superclass-->
<property name="XXX" type="Int"/>

<!--subclass map-->
<subclass name="SubClass1"
discriminator-value="SubClass1_discriminator">
<!--subclass1 properties-->
<property name="XXX" type="Int"/>
<property name="XXX" type="Int"/>
</subclass>
<subclass name="SubClass2"
discriminator-value="SubClass2_discriminator">
<!--subclass2 properties-->
<property name="XXX" type="Int"/>
<property name="XXX" type="Int"/>
</subclass>
</class>
</hibernate-mapping>


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