-->
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: Problem using merge with nested transactions
PostPosted: Tue Jan 23, 2007 8:17 pm 
Newbie

Joined: Wed Mar 15, 2006 5:37 pm
Posts: 3
I have a fairly common environment of spring 1 and hibernate 3 and I am having a problem when attempting the following (psuedo code):

1. start outer transaction
2. x = session.get(Foo.class, id)
3. add an item i to a blank collection on x (the collection is already there, im just adding an item, as opposed to adding a whole new collection)
4. start inner transaction (propagation = REQUIRES_NEW)
5. merge(x); // hibernate writes all properties on x's graph to database
6. commit inner transaction
7. commit outer transaction // hibernate flushes the session associated with this transaction, writing any properties that have changed since (2) to the database.

This results in 2 i's being inserted into that collections backing table, when I only added one. The problem is that hibernate flushes the same change twice. This only happens if x is read in one transaction and then merged in a nested transaction. Note that if the whole collection is replaced, this problem does not occur because each time the collection is flushed hibernate issues a delete statement before the inserts

I am using spring's HibernateTransactionManager and LocalSessionFactoryBean.

Are these kinds of nested transactions just incompatible with the merge operation? Any help would be greatly appreciated!!!


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.