wood burning stoves*
The moose likes Object Relational Mapping and the fly likes Hibernate Transaction delete commit fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Transaction delete commit fails" Watch "Hibernate Transaction delete commit fails" New topic

Hibernate Transaction delete commit fails

Damien Fergusson

Joined: Oct 17, 2009
Posts: 9
We have a business usecase where we need to delete a set of rows in a transaction!
The Object graph is very simple. Object 1 has CASCADE ALL as its attribute FYI:

Object 1 > One-to-Many > Object 2
We need to delete Object 2 entries.

On a local integration testing environment - we use org.springframework.transaction.jta.JtaTransactionManager for deleting the Hibernate entities - which works.
However, when deployed on the server, we use org.springframework.transaction.jta.WebSphereUowTransactionManager which throws this error:

0000002a RegisteredSyn E WTRN0074E:
Exception caught from before_completion synchronization operation: javax.persistence.EntityNotFoundException: deleted entity passed to persist:

at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:525)
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter$1.invoke
at $Proxy98.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65)
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:242)
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2449)
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1675)
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1646)
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1581)
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:247)
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:168)
at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:1056)
at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:1026)
at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:976)
at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:510)
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:252)

Can anyone suggest why it would pass when using org.springframework.transaction.jta.JtaTransactionManager but fails when using org.springframework.transaction.jta.WebSphereUowTransactionManager?
Damien Fergusson

Joined: Oct 17, 2009
Posts: 9
I managed to figure out what was wrong - pretty silly really!!
Anyways - posting here so anyone googling this issue might find this of help.

I was deleting the Object 2 thus:

However, I wasn't disassociating the Object 2 from Object 1 as well.
Before commit at anytime, in addition to deleting the target Object from the Entity Manager above, disassociate the Objects you are deleting from the parent object in the memory as well and this problem goes away.

This should fix the issue.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Hibernate Transaction delete commit fails
Similar Threads
Transaction Management in Spring
Transaction name null if WebsphereUowTransactionManager is configured
Doubt in SessionBean contract(ejb 3.0 core)
Exception when adding a child in one-to-many
How to remove and insert entity in same transaction?