-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need Help: Table per Class Inheritance
PostPosted: Thu Sep 30, 2010 5:28 am 
Newbie

Joined: Fri Sep 24, 2010 8:20 am
Posts: 5
Hello,

i have the following "Table per Class" szenario: C extends B and B extends A (with C and B inheriting the primary key ("id") of A) .
Which basically means that when an Object of Type C is created. All basic properties will be stored in the superclass A where the primary key is generated, the subproperties will be stored in B, and the Type specific properties in C. With a join over all 3 Tables using the common primary key, i get the full object C.

B extends A is easy to implement in a hbm.xml file with the <joined-subclass> Tag.

Code:
<class name="A">
   <id name="id"><generator class="native" /></id>
   <property name="..." />
   <joined-subclass name="B" table="B">
       <key column="id" />
       <property name="..." />
   </joined-subclass>
</class>


But how can i implement "C extends B" , so that C inherits the primary key of B.

If there is an easier way with Annotations tell me. I am used to hbm.xml-files but its not working all the ways i tried it.

Many thx in advance!
Michael


Top
 Profile  
 
 Post subject: Re: Need Help: Table per Class Inheritance
PostPosted: Fri Oct 01, 2010 6:01 am 
Newbie

Joined: Fri Sep 24, 2010 8:20 am
Posts: 5
nobody an idea ? I'm really lost!

M.


Top
 Profile  
 
 Post subject: Re: Need Help: Table per Class Inheritance
PostPosted: Fri Oct 01, 2010 7:14 am 
Newbie

Joined: Tue Feb 02, 2010 10:37 am
Posts: 13
Subclasses can be nested as described below:

<class name="A">
<id name="id"><generator class="native" /></id>
<property name="..." />
<joined-subclass name="B" table="B">
<key column="id" />
<property name="..." />
< joined-subclass name="C" table="C">
<key column="id" />
<property name="..." />
</joined-subclass>
</joined-subclass>
</class>


Top
 Profile  
 
 Post subject: Re: Need Help: Table per Class Inheritance
PostPosted: Fri Oct 01, 2010 9:15 am 
Newbie

Joined: Fri Sep 24, 2010 8:20 am
Posts: 5
Hello vijaybangy,

thx for your reply. But i think your example would reflect:

  • B is subclass auf A
  • C ist subclass of A.

What I need to describe is:
  • B is subclass auf A
  • C is subclass auf B

Of course this way C is also a sub-sub-class of A, you are right. But the way you put it, i would loose the relationships between B and C would I ?

Thx again for your help!


Top
 Profile  
 
 Post subject: Re: Need Help: Table per Class Inheritance
PostPosted: Tue Oct 05, 2010 10:07 am 
Newbie

Joined: Tue Feb 02, 2010 10:37 am
Posts: 13
mweidlich,
In my reply above i have nested one of <joined> inside another <joined>. So it's C subclass of B.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.