I use Hibernate with SubClasses enabled to map the class hierarchy to the database. Unfortunately, this causes locks when the object is updated while another thread is trying to load the same object. With objects that are displayed for a single table, this is not a problem. This seems to be caused by the way MSSQL gets locks on class hierarchy tables.
When Hibernate loads an object from the database, it uses SELECT with JOIN:
SELECT ...
FROM
subclass
LEFT JOIN class
ON ...
WHERE ...
When Hibernate updates an object of this subclass, it does the following:
UPDATE
class
SET ...
WHERE ...
UPDATE
subclass
SET ...
WHERE ...
The problem is that if an object is loading between two update statements, it causes a dead end. The SELECT statement blocks 2 tables after another. So it looks like:
- Topic 1 loads the object and places common locks on both tables.
- 1 UPDATE
.
- Thread 2 , SELECT,
, ,
- 1 UPDATE ,
,
2, 1
- 2 - 1
:
,
.
HSQLDB, , HSQLDB, ,
, , ,
MSSQL.
, Hibernate
( )?