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.
|