-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with parent/child mapping and table per class hierar
PostPosted: Fri Jul 27, 2007 8:19 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
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...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 12:07 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You've described the class as mutable="false" so no changes will be persisted.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 3:09 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
I was sure I had tried with both mutable="false" and "true", but obviously not...
You are of course right. Thanks, thatmikewilliams. :)


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