Hi
From the SybaseDialect class I can see that
select for update and
select for update no wait ins't suportetd. Does this mean that if I do
session.lock(anId, LockMode.UPGRADE) I do not really get the pessimstic lock I'm looking for? Form the code I found in
AbstractEntityPersister.initLockers(), I think for Sybase the instance is just "selected" again without acquiering any locks.
AFAIK in Sybase the "for update" is called
holdlock which means the SQL should look like this
Code:
select PID from TABLE_A holdlock where PID =? and SYSTEM_ID =?
Unfortunately I don't have a Sybase DB at hand to test this. The test you find below is done using MySql.
Best Regards
Ernst
Hibernate version: 2.1.4
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.ClassA" table="TABLE_A">
<composite-id name="pk" class="hello.CapiPK">
<key-property name="pid" column="PID"/>
<key-property name="systemId" column="SYSTEM_ID"/>
</composite-id>
<set name="B" table="TABLE_B" cascade="all" inverse="true">
<key>
<column name="A_PID"/>
<column name="SYSTEM_ID"/>
</key>
<one-to-many class="hello.ClassB"/>
</set>
<set name="C" table="TABLE_C" cascade="all" inverse="true">
<key>
<column name="A_PID"/>
<column name="SYSTEM_ID"/>
</key>
<one-to-many class="hello.ClassC"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session = sf.openSession(new CapiInterceptor());
tx = session.beginTransaction();
a = (ClassA) session.load(ClassA.class, a.getPk());
System.out.println("asking for lock ***********************************************");
session.lock(a, LockMode.UPGRADE);
System.out.println("has lock ***********************************************");
Set as = a.getB();
for (Iterator iter = as.iterator(); iter.hasNext();) {
ClassB element = (ClassB) iter.next();
element.setPayload("Hugo Habicht");
}
tx.commit();
session.close();
Full stack trace of any exception that occurs:no exceptions thrown
Name and version of the database you are using:MySQL 4.0.20a
Debug level Hibernate log excerpt:Code:
...
Hibernate: select classa0_.PID as PID0_, classa0_.SYSTEM_ID as SYSTEM_ID0_ from TABLE_A classa0_ where classa0_.PID=? and classa0_.SYSTEM_ID=?
Hibernate: select c0_.PID as PID__, c0_.SYSTEM_ID as SYSTEM_ID__, c0_.A_PID as A_PID__, c0_.PID as PID0_, c0_.SYSTEM_ID as SYSTEM_ID0_, c0_.A_PID as A_PID0_, c0_.SYSTEM_ID as SYSTEM_ID0_ from TABLE_C c0_ where c0_.A_PID=? and c0_.SYSTEM_ID=?
Hibernate: select b0_.PID as PID__, b0_.SYSTEM_ID as SYSTEM_ID__, b0_.A_PID as A_PID__, b0_.PID as PID0_, b0_.SYSTEM_ID as SYSTEM_ID0_, b0_.A_PID as A_PID0_, b0_.SYSTEM_ID as SYSTEM_ID0_, b0_.payload as payload0_ from TABLE_B b0_ where b0_.A_PID=? and b0_.SYSTEM_ID=?
asking for lock ***********************************************
Hibernate: select PID from TABLE_A where PID =? and SYSTEM_ID =? for update
has lock ***********************************************
Hibernate: update TABLE_B set A_PID=?, payload=? where PID=? and SYSTEM_ID=?
...