-->
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.  [ 1 post ] 
Author Message
 Post subject: Multi level hierarchy using joined subclass
PostPosted: Sat Jun 05, 2010 2:37 pm 
Newbie

Joined: Sat Jun 05, 2010 2:21 pm
Posts: 2
Hi

We are using Hibernate 2.x with hbm xml mapping and trying the following:
We have a 3 level inheritance hierarchy and are using table per subclass.
Class C extends Class B, Class B extends Class A.

The table structure is:
Table A has PK_A
Table B has PK_B and a separate column PK_A (which obviously is a foreign key to PK_A in table A)
Table C has PK_C and a separate column PK_B (which obviously is a foreign key to PK_B in table B)

ALL PKs have associated sequences in the database.

Code:
class A
{
     pkA;
}

class B extends A
{
     pkB;
}

class C extends B
{
     pkC;
}



The mapping looks like this:

Code:
<class
name="A"
table="TBL_A"
>
    <id
        name="pkA"
        type="java.lang.Integer"
        column="PK_A"
    >
        <generator class="sequence">
            <param name="sequence">A_SEQ</param>
        </generator>
    </id>
    <property...
</class>

<joined-subclass
        name="B"
        table="TBL_B"
       extends="A"
>
         <key column name="PK_A" />
         <property
                name="pkB"
                type="java.lang.Integer"
                column="PK_B"
                not-null="true"
          />
</joined-subclass>

<joined-subclass
        name="C"
        table="TBL_C"
       extends="B"
>
         <key column name="PK_B" />
          <property
                name="pkC"
                type="java.lang.Integer"
                column="PK_C"
                not-null="true"
          />
</joined-subclass>



I have the following questions:
1. is this the right approach ? and whether the mapping is correct.
2. Since "joined-subclass" tag will not support "id" tag like "class" tag does, how do i define the sequences for the separate PKs for the joined subclasses (e.g. PK_B and PK_C above)?


in Joined-subclass parent id down to the child tables. Unfortunately our requirements here demand that every child table have its own id which in turn is used as FK in other tables. This scenario is just part of the "whole" design!

For one I am curious as to how hibernate will handle this issue of a joined-subclass having its own id that is generated through a sequence. or i cant do that at all??

Thx


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.