I have a problem with getting a parent/child relationship working properly when using a table per class hierarchy mapping.
When I create two new SpecialItems, and set one as the others parent and execute create, the results are as expected. But when I retrieve two SpecialItems to set one as the others parent, nothing happens.
Hibernate version: 3.2.4.sp1
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.company.Item" table="item"
mutable="false" discriminator-value="0">
<id name="itemid" column="itemid">
<generator class="native" />
</id>
<discriminator column="ITEM_TYPE" type="integer"/>
<property name="name" type="string" />
<subclass name="com.company.SpecialItem" discriminator-value="1">
<many-to-one name="parentItem" class="com.company.Item" />
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():This works:Code:
SpecialItem item = new SpecialItem();
item.setName("Parent item");
SpecialItem itemchild = new SpecialItem();
itemchild.setName("Child item");
itemchild.setParentItem(item);
itemDao.createItem(item);
itemDao.createItem(itemchild);
This does not work:Code:
SpecialItem itemchild = itemDao.getItem(100);
SpecialItem item = itemDao.getItem(200);
itemchild.setParentItem(item);
itemDao.updateItem(itemchild);
Full stack trace of any exception that occurs:
No exception or error...
Name and version of the database you are using:
MySQL 5.0.41-community-nt
The generated SQL (show_sql=true):
In the "does not work" example sql is generated for the two first statements (two select statements).
Nothing for the update-functions...