-->
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.  [ 2 posts ] 
Author Message
 Post subject: Inheritance with "Table per Subclass" question
PostPosted: Sat Mar 31, 2007 6:44 am 
Newbie

Joined: Sat Mar 31, 2007 5:43 am
Posts: 1
Hibernate version:3.2

Hi,

I am attempting to map an existing database using hibernate. The database models the following structure

Code:
Class C extends Class B
Class B extends Class A


It implements this in this table structure

Code:
Table A primary key of A_ID(Identity - Auto Generated)
Table B primary key of B_ID(Identity - Auto Generated) + foreign key of A_ID to Table A
Table C primary key of C_ID(Identity - Auto Generated) + foreign key of B_ID to Table B

This is in keeping with the rest of the database that gives a unique id (primary key) for every table.

In trying to map this using Hibernate, I have chosen the "Table per Subclass" strategy. I have attempted various mappings, but not yet managed to successfully.

Here is one that I have tried.
Code:
<class name="ClassA" table="A"
    <id name="id" type="long"
        <column name="A_ID" />
        <generator class="native"/>
    </id>
</class>

<joined-subclass name="ClassB" extends="ClassA">
    <key column="B_ID"/>
</joined-subclass>

<joined-subclass name="ClassC" extends="ClassB">
    <key column="C_ID"/>
</joined-subclass>



When I use this to perform an insert, the first thing that happens is that an insert to table A happens, and it returns the generated id. It then inserts to Table B, supplying the id obtained from Table A. It then inserts to Table C, but uses the id still from Table A. This causes a foreign key violation on Table C to Table B.

It is almost as if the assumption is that the key used to join to the base class has to be the primary key of the table.

I have tried to put an <id> and a <key> in the <joined-subclass>, but the DTD doesn't allow this. I suspect what I need to do is define the "identity" in the mapping to be independent of the inheritance keys, but I haven't found how to do this.

I am not sure if I have explained this too well. Any pointers and help will be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 10:16 am 
Newbie

Joined: Fri Mar 03, 2006 5:55 am
Posts: 7
Anyone has any ideas on this topic ?


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