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