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
|