Java Mailing List Archive

http://www.java2.5341.com/

Home » user-java.ibatis »

Concurrency Issue With Rollback

quinya

2009-10-12


Author LoginPost Reply

Hi,

I am using a timestamp to manage concurrency. But I'm having a problem when
a transaction is rolled back.

I update the timestamp when the object is saved. It works great. But if the
save is just one part of the transaction and the transaction fails and rolls
back, then the object is left with a timestamp that is not consistent with
what in the database. That is - the database save is rolled back, but the
timestamp in the object is not.

I think I must just be going about this the wrong way. I don't remember ever
having this issue in the past. Can anyone point me in the right direction?


My DAO method looks like this:

myObject.setUpdatedTime(new Date());
getSqlMapClientTemplate().update("updateQuery", myObject);
myObject.syncOldUpdatedTime();


The Object looks like:

protected Date updatedTime = new Date();
protected Date oldUpdatedTime = null;
public void syncOldUpdatedTime() {
 this.oldUpdatedTime = this.updatedTime ;
}


The mapping and SQL look like:

    <resultMap id="thingResultMap" class="thingObject">
   <result property="id" column="id"/>
   <result property="code" column="code"/>
   <result property="name" column="name"/>
   <result property="updatedTime" column="updated_time"/>
   <result property="oldUpdatedTime" column="updated_time"/>
 </resultMap>

 <update id="update" parameterClass="thingObject">
   update $type$
   set
     name = #name#,
     code = #code#,
     updated_time = #updatedTime#
   where
     id = #id#
   and
     updated_time = #oldUpdatedTime#
 </update>


--
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@(protected)
For additional commands, e-mail: user-java-help@(protected)

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.