-->
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: setting collection does not remove the old objects
PostPosted: Fri Feb 13, 2009 3:41 pm 
Newbie

Joined: Fri Feb 13, 2009 1:02 pm
Posts: 1
Hello,
I'm using hibernate 3.3.1 GA version. This is my use case. I have a parent with child objects. My first call to the server returns the parent with all the child objects. The client then performs some operation and return new set of child objects. My DAO code basically reconstructs the child and set all these incoming child objects. The child object could be any one of the persisted child objects. When the code sets the child objects on the parent and update the changes, only the update/insert operation are being performed. The previous child objects are not removed from datastore. I'm pretty sure that it is a common use case and there is something that I'm missing to achieve the purpose. Could some one please point me in the right direction? Thanks.

Parent mapping:
<set name="attributes" inverse="true" cascade="all,delete-orphan">
<key column="USR_RPT_I"/>
<one-to-many class="com.ejgallo.icc.ussc.bo.UserReportAttribute"/>
</set>

Child mapping:
<many-to-one name="userReport" column="USR_RPT_I" not-null="true"/>

Code to persist the changes:
Service layer build the persistent object and sends it to the DAO to persist the changes.

service layer:
UserReport report = new UserReport();
report.setId(<previously persisted id>);
Set attributes = new HashSet();
UserReportAttribute attr = new UserReportAttribute();
attr.setId(<previously persisted id>);
attributes.add(att);
UserReportAttribute attr2 = new UserReportAttribute();
attr2.setId(<new id..not yet persisted>);
attributes.add(attr2);
report.setAttributes(attributes);

calls DAO with the persistence capable object, report.
DAO layer:
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
HibernateUtil.getSessionFactory().getCurrentSession().update(report);
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();

Say for eg. this report with id with 5 child attributes, and on this update process, I'm sending one new attribute and 1 updated attribute. So I'm expecting the hibernate to issue 4 delete query, 1 insert query, 1 update query. However, hibernate issues only 1 insert, 1 update. It does noto issue the delete queries. What I'm missing here?

Thanks for your time.


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.