-->
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: unidirectional association with table per concrete class
PostPosted: Wed Oct 19, 2005 11:59 pm 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 6
I have abstract class A and its 2 concrete subclasses ASub1 and ASub2. There is another class B associated with A.
If the association is bidirectional, then we can use <any> or <many-to-any> tag in B.hbm.xml
But what will be the mapping if the association is unidirectional from A to B???
Please help me with this. It's urgent.
Thanks in advance.


Top
 Profile  
 
 Post subject: please clarify
PostPosted: Fri Oct 21, 2005 11:33 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Do you mean that A simply have collection of Bs? or simply references B?

Than just use many-to-one
http://www.hibernate.org/hib_docs/v3/re ... -manytoone
Or one of collection tags on a.hbm.xml

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Details given : Please reply ASAP. thanx
PostPosted: Mon Oct 24, 2005 12:30 am 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 6
[img]D:\inheritance.JPG[/img]

abstract class A
class ASub1 extends A
class ASub2 extends A
class B

A__1___________________________________0..*__B


If the association between abstract class A and B is bidirectional, then the mapping will be as follows
<hibernate-mapping package="many2one">
<class table="B" name="B">
<id type="java.lang.Long" column="ID" name="id">
<generator class="increment"/>
</id>
<any name="A" meta-type="string" id-type="java.lang.Long">
<meta-value class="ASub1" value=" ASub1"/>
<meta-value class="ASub2" value=" ASub2"/>
<column name="A_CLASSNAME"/>
<column name="A_ID"/>
</any>
</class>
</hibernate-mapping>

<hibernate-mapping package="many2one">
<class table="ASub1" name="ASub1">
<id type="java.lang.Long" column="ID" name="id">
<generator class="increment"/>
</id>
<set inverse="true" name="bs">
<key column="A_ID"/>
<one-to-many class="B"/>
</set>
</class>
</hibernate-mapping>

<hibernate-mapping package="many2one">
<class table="ASub2" name="ASub2">
<id type="java.lang.Long" column="ID" name="id">
<generator class="increment"/>
</id>
<set inverse="true" name="bs">
<key column="A_ID"/>
<one-to-many class="B"/>
</set>
</class>
</hibernate-mapping>

But if the association between abstract class A and B is unidirectional from A to B, then we can’t specify <any> tag in B.hbm.xml. foreign key column “A_ID” can be specified in the ASub1.hbm.xml and ASub2.hbm.xml. But there is no place where we can specify column “A_CLASSNAME”.

how to map this in case of unidirectional association with tabla per concrete class?


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.