Hibernate version: 2.1
Name and version of the database you are using: MSSQL wit jtds drivers and JDBC transactions
Hi,
I want to use multiple sessions generated from the same database and session factory to implement a application locking table.
The locking table is used to block parts of my application from concurrent modification. It follows a quite simple approach: Fill the object key (primary key) of the object you want to lock into a database table.
To make the lock row visible to other applications (multiple servlets are accessing this database, all are using hibernate and all are using the same system-wide db-pool) it is required to have it created and removed in a seperate transaction.
I tried this using a standalone application that created two sessions and used the hibernate provided c3p0 pool. This worked as expected, no deadlocks.
Session A opens transaction accesses an instance of Object X.
Session B opens transaction and writes keyOf(X) to LockTable, this will fail if this key is already present (unique index). Session B commits transaction.
Session A works on X and persists X, transaction commits
Session B opens transaction removes keyOf(X) from LockTable
When doing this in my tomcat 5.5.9 container, where dbcp is used, Session B will hang in a deadlock when trying to write the lock. No exceptions are thrown. This seems to be a lock at the database level and I tried to debug the hibernate code just to find, that it seems that both sessions used the same connection object. Could this be the reason for this?
Did anyone else experience similar behaviour? I am currently also evaluating writing a locking service, that will be completely independent from applications requesting locks, but I do not know if this will kill my performance and it adds a single point of failure in the system.
Hoping for ideas,
Thomas
_________________ --
"No, you don't!", Jack Bauer to Nina in "24"
|