I am having a deadlock issue in multi-threading environment if "insert and update of the same object" is performed within the same transaction. Point is that hibernate performs two operations (instead of one) when thread creates one object then updates the same object . Second operation is deadlocking with another thread that is doing the same job. I expected hibernate reconciles update and insert because both of them are performed before then do a flush. Record that is inserted is not yet persisted when update is requested. It looks like that second update is absolutly undesired.
I tested this issue with HB 2.1 and 3.1 - both with the same results. Configuration is SQL Server, HILO generator is used for PK. Two processes are continiously performing the same operation in the separate JVMs.
As a result I see insert object x update object x Why does not hibernate reconcile insert and update ?
[ October 27, 2005: Message edited by: Stas Sakalou ] [ October 27, 2005: Message edited by: Stas Sakalou ]
There are no relationships mapped. Can you just for curiosity sake, make one simple test. You have to create a class with only one method main. In the main method you have to create a session then initialize a new object, and then save it. Update one of the fields of the object and flush the session. Check hibernate SQL trace. Does it perform 2 operations? ?
Joined: Aug 24, 2005
I tried it. Hibernate performed 2 operations.
Hibernate is mirroring in sql the operations I performed on the POJOs.
That's really the safe approach. It could cause problems if Hibernate combined statements (or eliminated statements in the case of an insert + a delete.)
For example, triggers might not fire or operations might not cascade correctly.
On my current project, I have an inventory value that my application should insert but never update. If Hibernate combined statements, I could end up with an incorrect value. [ October 30, 2005: Message edited by: Scott Johnson ]