-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cannot lock Informix row using LockMode.UPGRADE
PostPosted: Wed Jul 25, 2007 1:55 pm 
Newbie

Joined: Thu Jun 07, 2007 11:28 am
Posts: 2
Location: Woking, UK
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.