-->
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: Unable to map an one-to-many association to an ideal-databa
PostPosted: Thu Dec 08, 2005 2:43 am 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 6
Hibernate version: Hibernate 3.0.5

Consider a scenario as shown in Fig. 1. Here the hierarchy of P is mapped using Table-Per-ClassHierarchy and that of X is mapped using Table-Per-ConcreteClass. The cardinality of association is one-to-many (from P to X) and the association is bidirectional.

<<See attachment: Fig1.jpg>>Figure 1 Class Diagram containing an association

The ideal database schema for this association would be as shown in Fig 2.

<<See attachment: Fig2.jpg>>Figure 2 Ideal Database Schema
But as I don’t know much hibernate-mapping-tags, I have mapped this using following hbm files:

P.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="chsncc.bi.one2many">
<class name="P" table="PTEST">
<id name="id" column="ID" type="java.lang.Long">
<generator class="increment"/>
</id>
<set name="xs" table="P_XTEST">
<key column="P_ID"/>
<many-to-any meta-type="string" id-type="long">
<meta-value value="Z1" class="Z1"/>
<meta-value value="Z2" class="Z2"/>
<column name="X_CLASSNAME"/>
<column name="X_ID"/>
</many-to-any>
</set>
</class>
</hibernate-mapping>

Z1.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="chsncc.bi.one2many">
<class name="Z1" table="Z1TEST">
<id name="id" column="ID" type="java.lang.Long">
<generator class="increment"/>
</id>
<join table="P_XTEST" inverse="true">
<key column="X_ID"/>
<many-to-one name="p" column="P_ID"/>
</join>
</class>
</hibernate-mapping>

Z2.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="chsncc.bi.one2many">
<class name="Z2" table="Z2TEST">
<id name="id" column="ID" type="java.lang.Long">
<generator class="increment"/>
</id>
<join table="P_XTEST" inverse="true">
<key column="X_ID"/>
<many-to-one name="p" column="P_ID"/>
</join>
</class>
</hibernate-mapping>

And the resultant database schema is as shown in Fig. 3.


<<See attachment: Fig3.jpg>>Figure 3 The resultant database schema
This requires an extra table to be created.

Is there any way by which I can map it to the ideal schema?

Thanks in advance.
[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:49 am 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 6
[img]C:/Fig1.JPG[/img]
[img]C:/Fig2.JPG[/img]
[img]C:/Fig3.JPG[/img][/url]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 12:58 am 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 6
there was some problem attaching images. hence reentered the issue.
please refer to : http://forum.hibernate.org/viewtopic.ph ... highlight=


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.