-->
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.  [ 6 posts ] 
Author Message
 Post subject: joined subclass - multi level hierarchy
PostPosted: Mon Apr 18, 2005 12:21 pm 
Newbie

Joined: Thu Mar 10, 2005 8:11 pm
Posts: 9
Hi

We are using Hibernate 3.0 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.

The class design is
Code:
class A
{
     pkA;
}

class B
{
     pkA;
     pkB;
}

class C
{
     pkB;
     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)?

Thanks!
Amol


Top
 Profile  
 
 Post subject: joined subclass - multi level hierarchy
PostPosted: Mon Apr 18, 2005 4:06 pm 
Newbie

Joined: Thu Mar 10, 2005 8:11 pm
Posts: 9
Apologies, the class design is as follows:

Code:
class A
{
     pkA;
}

class B extends A
{
     pkB;
}

class C extends B
{
     pkC;
}


Looking forward to any kind of help,

Amol


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 7:21 am 
Beginner
Beginner

Joined: Thu Oct 16, 2003 7:30 am
Posts: 21
Location: Brussels
In fact, PK_A=PK_B=PK_C, and only class A needs an id. As class B and C are subclasses of A they inherit this id:

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="FK_A" />
         <!-- real properties belonging to B -->
</joined-subclass>

<joined-subclass
        name="C"
        table="TBL_C"
       extends="B"
>
         <key column name="FK_A" />
          <!-- real properties belonging to C -->
</joined-subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 9:46 am 
Newbie

Joined: Thu Mar 10, 2005 8:11 pm
Posts: 9
Hi jandries,

Thank you for the reply.

You are correct in terms of trickling down a 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??

Thanks
Amol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 5:44 am 
Newbie

Joined: Mon Aug 08, 2005 5:24 am
Posts: 1
Amol,

Have you already solved this inheritance problem? I have the same problem and I'm also designed-bound concerning the trickling of the parent ID (so I'm having C_pf = B_pk and B_fk = A_pk).

Thanks,
martijn


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 10:14 am 
Newbie

Joined: Thu Mar 10, 2005 8:11 pm
Posts: 9
I could not find a "legal" way of doing this. We have set the A_pk, B_pk, C_pk as normal properties and NOT as <id>s! and since we have to set these ids through sequences in the DB, we are setting these values physically before we do a create operation. This solution is not what we would want to do - but I couldnt think of another way. And as per our reqts unfortunately we cannot do away with these ids.
If you can think of any other way - or if anybody else who might be reading this - replies are welcome.

Thanks
Amol


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