Hibernate version: 3.2.1
Informix Version: 7.3.1
Spring 1.2
I am using Spring and annotations.
I am attempting to find a row using a Generic method FindById, update fields in that row, then persist that row.
If I do this using ESQL/C using a cursor, and select ... for update two lock records are created in syslocks: IX, and U for rowid. I cannot then update the row elsewhere until it's released - good!
However, I have a Java method that uses LockMode.UPGRADE, and only the IX lock is generated, and it's possible to update the row outside of hibernate, thus causing stale data - bad!
My code:
Code:
private void myMethod(...) {
...
MyTable myTable = myTableDAO.findById(myPK);
<BREAKPOINT>
myTable.setField1("Whatever");
myTableDAO.update(myTable);
}
... class GenericDAO ... {
private Class<T> persistentClass;
public T findById(PK id) {
T entity;
entity = (T) getSession().load(persistentClass, id, LockMode.UPGRADE);
return entity;
}
When stopped at the BREAKPOINT, the myTable bean has been successfully retrieved and looks great - the SQL generated has "for update" at the end.
In Informix, there is an "IX" lock, but NO "U" lock - suggesting that the row is NOT locked; and if I enter an update query into Informix (using dbaccess or an ESQL/C program) I can update the row!!
When I continue with program execution, I get stale data and then problems.
I want to lock the rows (as suggested in page 466 of the Java Persistance with Hibernate book).
My relevant spring bean snippets:
Code:
<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager" /></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED</prop>
...
Many thanks for any help.