-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: session deadlock when 2 threads access same tables
PostPosted: Tue May 23, 2006 3:39 pm 
Newbie

Joined: Tue Mar 21, 2006 3:19 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.2

Mapping documents:
A.hbm.xml and B.hbm.xml and AB.hbm.xml (many-many between A and B) All tables have ID (native) and version columns.


Code between sessionFactory.openSession() and session.close():
trans = session.beginTransaction();
ADAO aDAO = DAOFACTORY.getADAO();
A a = aDAO.findById(id);
BDAO bDAO = DAOFACTORY.getBDAO();
B b = bDAO.findByName(name);
if(b== null){
b = new B(name);
bDAO.makePersistent(b);
a.addB(b); // adds b to a and a to b (many-many)
}
aDAO.makePersistent(a);
trans.commit();




Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 10g Enterprise edition 10.2.0.1.0 (ojdbc14.jar with Java 1.5 and Tomcat 5.5)

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I have 2 simple tables A and B and another table which is a many-many mapping between the 2 tables (AB). I am running Hibernate 3.1.2 from within Tomcat 5.5 (using Tomcat's JDBC pool) on a Oracle 10g Enterprise Edition database. I start 2 threads from within a servlet's init method which do the exact same thing which is listed in the code above. (Very simple classes and follow CaveatEmptor application semantics -DAO etc)
In the code above, both threads extract the same version numbers for a object. Both come to the commit stage(issue trans.commit) and are now blocked.
From Oracle Enterprise Manager console this is what I see...
SessionID LockType ModeHeld ModeRequested ObjectType ObjectName
128 TX EXCLUSIVE NONE TABLE AB
130 TX NONE SHARE
130 is blocked on 128
128 details
Status : INACTIVE
Previous SQL : insert into B....
Open cursors : 10
130
Status : ACTIVE
Current SQL : insert into AB....
Current Wait Event enq: TX - row lock contention
Current Wait Class Application

Expected behavior is first thread would commit the row and update version number and when second thread tries to update a StaleObjectExcp is thrown. But I am not sure why the first thread's database session has become inactive and it never releases the lock on the table.
The second thread's DB session is now waiting indefinitely for that lock. After this point we are not able to execute any further operations using Hibernate.
Any advice is helpful... Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 6:54 pm 
Newbie

Joined: Tue Mar 21, 2006 3:19 pm
Posts: 2
We figured it out. It was an application level logic that was causing a deadlock across multiple domains. (Lock in code was waiting for lock from db and vice versa).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.