concurrency - Retrying after StaleObjectStateException in a hibernate batch -


hibernate version : 3.2.6.ga

spring(transactions) : 3.1.1

i facing in batch process don't have notify end user ,just need reload entities involved & redo work.

however, after catching staleobjectstateexception & reloading entity, still running staleobjectstateexception..why that?

more details on how reproducing after code...

    @requestmapping("testconcurrent/{entityid}/{version}")     @get     @transactional     public void testconcurrent(@pathvariable("entityid") integer entityid,              @pathvariable("version") integer version){          try{         updatedata(entityid, version);         sessionfactory.getcurrentsession().flush();         }         catch(staleobjectstateexception|optimisticlockexception e){             log.info("retrying due concurrency error");             updatedata(entityid, version);         }         catch(exception e){             log.info("some other error");         }     }       public void updatedata(integer entityid, integer version) {         entity entity = entitydao.getentitybyid(entityid);         entity.setupdated(dateutils.getcurrenttime());             entity.setversion(version.longvalue());              entitydao.createorupdateentity(crp);     } 

how reproduce concurrency:

1)i call testconcurrent given object version, stop debug flow @ last line in updatedata method.

2)then call testconcurrent again same object other version, , finish flow. reflects in db instantaneously have flush() after method returns.

3)now when continue first thread(which blocked in step 1), throws staleobjectstateexception expected & gets caught, calls updatedata method again , when fetch object db(entitydao.getentitybyid); throws same staleobjectstate exception again. why should when reloading latest object database?

this exception stacktrace way , not synchronize database state session org.hibernate.staleobjectstateexception: row updated or deleted transaction (or unsaved-value mapping incorrect):


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -