-->
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: saveOrUpdate on two new records in parallel in Hibernate 3
PostPosted: Mon Jul 06, 2009 4:26 pm 
Newbie

Joined: Mon Jul 06, 2009 4:02 pm
Posts: 1
I've searched the forums for this, but haven't found an exact match. Can someone explain the expected behavior from hibernate 3 for this scenario?

Two different threads (or processes) want to do saveOrUpdate within separate transactions (with commit/flush/close) for an entity with the same ID (enforced as primary key in the database).

The object does not yet exist in the database before these two threads race to do the save.

This works fine normally (one thread inserts, other updates) until the race occurs when the second thread gets a ConstraintViolationException for violating the primary key (both threads attempted an insert).

If Hibernate is not handling this condition, I'm not sure when I would ever rely on this method. Doing a try on saveOrUpdate then an update in an exception handler looks illogical on the face of it. Is there a piece I'm missing? I see mention of unsaved-value but I don't see how it applies to this case. Is caching involved? I tried disabling any sort of query and 2nd level caching without improvement.

Thanks for any help,
--jg


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.