Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Spring and the fly likes Spring - Hibernate Multithreading Transaction Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring - Hibernate Multithreading Transaction Issue" Watch "Spring - Hibernate Multithreading Transaction Issue" New topic

Spring - Hibernate Multithreading Transaction Issue

rudreshashok kumar

Joined: Aug 27, 2006
Posts: 16
Hi All,

I am facing a issue with Transaction management during multi-threading on db layer.

Application is built using spring for integration and hibernate for persistance (3.X). Transactions are handled by Container. Requests are served by MDB(2.1).

Object relations are as follows
Configurations is one object and different products can be created based on this configurations

Configurations --> one to many relation with Products

Application works fine with single thread, during multi threading, the persistance layer fails with deadlock issue even for two concurrent messages.

From logs could find that if one thread is working updating persistance layer and if another thread too starts updating another set of record (both messages are unique), dead lock occurs. Ideally lock on a table during update is row level, but seems like it is locking entire table (may be even due to parent child relations).

If the other thread starts after previous thread completes it works.

Errors :-
org.springframework.dao.CannotAcquireLockException: could not update: [com.xx.Products#10180873]; SQL [update Products set Prod_ID=?... where PROD_TID=?]; nested exception is org.hibernate.exception.LockAcquisitionException: could not update: [com.xx.Products#10180873]
Caused by: java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource

Hibernate confirgurations
<prop key="hibernate.order_inserts">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.batch_size>0</prop>">
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Its an Oracle error. You can get deadlock for things other than row locks : Check you indexes, cascading deletes, triggers etc. In short, you need to check at database level.

===Vyas Sanzgiri===
My Blog
abani patra
Ranch Hand

Joined: Oct 11, 2011
Posts: 70
Are you using it as web application or standalone application ?
I agree. Here's the link:
subject: Spring - Hibernate Multithreading Transaction Issue
It's not a secret anymore!