Deadlock
ido.ran Dec 11, 2009 3:53 AMHi,
I've been using Envers for a while now, currently only to collect audit information not using it yet.
Today I run into a SQL Server deadlock problem because I start to things concurrently.
I'm not jumping into conclusion to say that because of Envers I have the deadlocks, but when I remove Envers listeners from persistence.xml the deadlocks go away.
I'm using Glassfish V2.1 and EJB3 JPA with Hibernate as providers and Envers hookup.
The backend database is SQL Server Express (mounted database, not database file) and Microsoft JDBC type 4 database driver.
My case is that I delete an entity which cascade the delete to all it's related entities (specifically process contain collection of activities which contain collection of properties).
When I try to concurrently delete 3 processes (each one under it's own transaction off course) I get the following exception(s):
239797 [httpSSLWorkerThread-8080-3] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1205, SQLState: 40001
239797 [httpSSLWorkerThread-8080-3] ERROR org.hibernate.util.JDBCExceptionReporter - Transaction (Process ID 55) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
239797 [httpSSLWorkerThread-8080-3] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.LockAcquisitionException: could not delete: [org.dna.aurora.core.Activity#8f8e4fd8-9c56-4f97-a994-c6aa1d90570e]
few lines bellow it there is this exception:
240093 [httpSSLWorkerThread-8080-3] ERROR org.hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: possible nonthreadsafe access to session
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:107)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
and it appear once again, since I try to delete 3 entities, 2 of them got deadlock victim and were rollback.
What should I do differently?
Thank you,
Ido.