-->
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.  [ 2 posts ] 
Author Message
 Post subject: Collection of values update - problem
PostPosted: Tue Mar 21, 2006 6:09 am 
Newbie

Joined: Tue Mar 21, 2006 5:22 am
Posts: 5
Hi all,
I have the following mapping:
<class name="com.pjuza.oncology.domain.Record" table="records">
<id name="id" column="record_id">
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" type="string" not-null="true" />
<property name="lastName" column="last_name" type="string" not-null="true" />
<many-to-one name="picObjectParam" column="pic_obj_param" not-null="true"/>
<set name="pictureURLs" table="record_images">
<key column="record_id"/>
<element type="string" column="image_name"/>
</set>
</class>

Thus there is one class (Record) that is mapped from more db tables: records, record_images.

I have problem with updating of collection "pictureURLs". I use this scenario:
1) get Record object from db (get()) - REC1
2) change object's values in GUI - REC_NEW
3) update Record (REC_NEW) - everything ok (items in tables records, record_images were changed)
4) error occured in my application - I need to change state as before update.
5) call update Record (REC1) - ONLY "records" table was changed, NOT "record_images".

(REC1 and REC_NEW are different instances)

I have tryed different approaches and without results. Don't have anybody hints?

One note: I use Spring with Hibernate and I use transaction control (org.springframework.orm.hibernate3.HibernateTransactionManager) from Spring...

Thank you very much for a help.
PETER


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 6:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The most likely explanation is due to proxying. When you save REC_NEW, its collection is put into the session cache. Because you retrieved REC1 from the same session, this means that its collection is the same one, and therefore is updated with the new values. This is the way hibernate is designed. To continue to use your current design, you must detach REC1 before modifying REC_NEW (session.evict(REC1)). A better approach, if it's possible, is to use only REC1, removing the need for REC_NEW. And if there's an error in your application, roll back the transaction.


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