Apparently, if I 'save' a new object, change the data, and then flush it generates an insert with the initial values from the 'save' and then an update with the current data.
Is there a good reason for this behavior?
We made the change below to sessionimpl, which effectively replaces an insert with the new data rather than doing both an insert and an update when flushing a new object. It is a requirement for us because the insert and update are using different lock modes, which causes frequent deadlocks.
Is the change below a viable patch, or would it cause problems in areas we're unaware of?
Thanks for your help!
Jenica
--- SessionImpl.java 4 Feb 2004 23:59:27 -0000 1.4
+++ SessionImpl.java 20 Feb 2004 19:53:00 -0000 1.5
@@ -1,4 +1,4 @@
-//$Id: SessionImpl.java,v 1.4 2004/02/04 23:59:27 ron Exp $
+//$Id: SessionImpl.java,v 1.5 2004/02/20 19:53:00 ron Exp $
package net.sf.hibernate.impl;
import java.io.IOException;
@@ -2534,13 +2534,30 @@
checkNullability(values, persister, true);
- // schedule the update
- updates.add(
- //new Key(entry.id, persister),
- new ScheduledUpdate(entry.id, values, dirtyProperties, entry.loadedState, entry.version, nextVersion, object, updatedState, persister, this)
- //note that we intentionally did _not_ pass in currentPersistentState!
- );
-
+ // insert already scheduled?
+ // then just switch it!
+ boolean alreadyInserted = false;
+ int index = 0;
+ if ( insertions.size() > 0) {
+ for (Iterator i = insertions.iterator(); i.hasNext(); index++) {
+ ScheduledInsertion si = (ScheduledInsertion) i.next();
+ if (si.getInstance().equals(object)) {
+ alreadyInserted = true;
+ break;
+ }
+ }
+ }
+ if (alreadyInserted) {
+ insertions.remove(index);
+ insertions.add(index, new ScheduledInsertion( entry.id, values, object, persister, this ) );
+ } else {
+ // schedule the update
+ updates.add(
+ //new Key(entry.id, persister),
+ new ScheduledUpdate(entry.id, values, dirtyProperties, entry.loadedState, entry.version, nextVersion, object, updatedState, persister, this)
+ //note that we intentionally did _not_ pass in currentPersistentState!
+ );
+ }
}
if (status==DELETED) {
|