-->
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: Mapping inheritance with auto_increment id for child classes
PostPosted: Fri Mar 30, 2007 8:50 am 
Newbie

Joined: Fri Mar 30, 2007 8:19 am
Posts: 6
Hibernate version:

hibernate-3.2.0cr1

Mapping documents:

<class name="ParentClass" table="parents">
<id name="id" column="itemId" unsaved-value="-1">
<generator class="native"/>
</id>
<property name="parentProp1"/>
<property name="parentProp2"/>
<joined-subclass name="FirstChild" table="firstChilds">
<key column="firstChildId" />
<property name="firstChildProp1"/>
<property name="firstChildProp2"/>
</joined-subclass>
<joined-subclass name="SecondChild" table="secondChilds">
<key column="secondChildId"/>
<property name="secondChildProp1"/>
<property name="secondChildProp2"/>
</joined-subclass>
</class>

Name and version of the database you are using:

mysql-4.1.12

Hi.

I have an inheritance configuration mapped as show above, with a parent class and several child classes whith a table-per-subclass aproach.
What I want to achieve is to have a unique ID per child, and not globally unique, being autogenerated by the database, meaning that I want to generate an object of class FirstChild which gets an Id of 1 at the time of saving, generate a second object of class FirstChild, which gets an Id of 2, and a third object of class SecondChild, which gets an Id of 1 again. Current mapping generates an Id of 3 for that SecondChild object.

The way I'm solving this issue is by modifing the database by hand after the atomated creation vía hmb2dll. What I do is remove the primary key that has being created for child classes tables, and generate a new column, primary key and auto_increment for each of those tables. I add that same field to the ParentClass, and to the mapping file, but I do that after the hbm2dll creation, so that column won't be generated on the parents table.

What I'd like to help me with is in a way of mapping this situation so I don't have to modify myself the database.

Of course, I've been surfing the web and the forums. Very few references about the topic, and any of them pointed to a mapping solution.

Thanks in advance.


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.