• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.persistence.PersistenceException: org.hibernate.exception.LockAcquisitionException

 
Ashutosh Arya
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting the below error in an environment where I am having a vertical cluster of servers which are trying to execute a code in parallel (via separate JVM calls).

This code contains

The error which I am getting is:

javax.persistence.PersistenceException: org.hibernate.exception.LockAcquisitionException: could not lock: [dataBaseObject#174]
Impl.JCLLoggerAdapter error ORA-00060: deadlock detected while waiting for resource

It seems that the calls from several JVMs is creating a deadlock as the resource is locked (by above mentioned code to avoid dirty reads or non-repeatable rows).

What is the best possible solution for this scenario to avoid deadlocks?

Thanks in advance.
 
Martin Vajsar
Sheriff
Pie
Posts: 3751
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your database always Oracle? In Oracle, dirty reads are not possible, and non-repeatable reads could be avoided using serializable or read-only transactions (I'm not sure whether it is possible to use read-only transaction with Hibernate, though, and serializable isolation level can bring up problems of its own). On top of that, single queries are always self-consistent. Taking this into consideration could perhaps allow you to modify your logic to avoid explicit locking.

Other than that, the solution to avoid deadlocks is always the same: all clients need to lock objects in the same order. It can be easier said than done, as database locks are generally created on various DML operations. In Oracle the situation is easier compared to some other databases, as locks are never obtained for reading, only for updates (and, of course, for explicit locking, which includes SELECT FOR UPDATE).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic