Announcement Announcement Module
Collapse
No announcement yet.
Spring Hibernate Concurrency Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Hibernate Concurrency

    Hi, I am updating the same object from two different browers.
    One browser succesfully saves ok. However, the other browser when I save
    throws an error StaleObjectStateException. I am expecting the exception
    but the problem I am having is that the database is being updated and a rollback is not occuring.

    In the code below the exception gets caught in the controller. No exceptions thrown within the service.
    If I uncomment the part //test rollback then nothing gets written to the database.
    Maybe it has something to do with the proxy it creates ? no annotations on the iterface

    @Controller
    try {
    updateAgreementFacade.updateAgreement();
    } catch (Exception e) {
    e.printStackTrace();
    }

    @Service("updateAgreementFacade") {

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void updateAgreement() {
    agreementRepository.saveAgreement(pCommand.getAgre ement());
    //test rollback
    //if (true) {
    // logger.debug("updateAgreement ABOUNT TO THROW EXCEPTION");
    //throw new RuntimeException();
    //}
    }
    }

    @Repository("agreementRepository")
    public void saveAgreement(Agreement pAgreement) {
    hibernateTemplate.saveOrUpdate(pAgreement);
    }


    15:59:43.544 [WebContainer : 12] ERROR o.h.e.d.AbstractFlushingEventListener - Could not synchronize database state with session
    org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.ricoh.erp.staging.sop.domain.Agreement#49200]
    at org.hibernate.persister.entity.AbstractEntityPersi ster.check(AbstractEntityPersister.java:1932) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.persister.entity.AbstractEntityPersi ster.update(AbstractEntityPersister.java:2576) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.persister.entity.AbstractEntityPersi ster.updateOrInsert(AbstractEntityPersister.java:2 476) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.persister.entity.AbstractEntityPersi ster.update(AbstractEntityPersister.java:2803) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.action.EntityUpdateAction.execute(En tityUpdateAction.java:113) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.engine.ActionQueue.execute(ActionQue ue.java:273) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:265) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:185) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321) ~[hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:51) [hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1216) [hibernate-core-3.6.0.1.Final.jar:3.6.0.1.Final]
    at org.springframework.orm.hibernate3.SpringSessionSy nchronization.beforeCommit(SpringSessionSynchroniz ation.java:145) [spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.transaction.support.Transactio nSynchronizationUtils.triggerBeforeCommit(Transact ionSynchronizationUtils.java:95) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.triggerBeforeCommit(Abstr actPlatformTransactionManager.java:927) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.transaction.jta.WebSphereUowTr ansactionManager.access$4(WebSphereUowTransactionM anager.java:1) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.transaction.jta.WebSphereUowTr ansactionManager$UOWActionAdapter.run(WebSphereUow TransactionManager.java:338) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWMa nagerImpl.java:1115) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManag erImpl.java:629) [com.ibm.ws.runtime.jar:na]
    at org.springframework.transaction.jta.WebSphereUowTr ansactionManager.execute(WebSphereUowTransactionMa nager.java:281) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:127) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at $Proxy1256.updateAgreement(Unknown Source) [na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) ~[na:1.6.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:60) ~[na:1.6.0]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:37) ~[na:1.6.0]
    at java.lang.reflect.Method.invoke(Method.java:611) ~[na:1.6.0]
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:309) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at com.ricoh.operation.interceptor.VerifyAgreementLoc kInterceptor.invoke(VerifyAgreementLockInterceptor .java:41) [classes/:na]
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at $Proxy1257.updateAgreement(Unknown Source) [na:na]
    at com.ricoh.operation.agreement.controller.ProductCo nfigurationController.process(ProductConfiguration Controller.java:288) [classes/:na]
    at com.ricoh.operation.agreement.controller.ProductCo nfigurationController.processConfiguration(Product ConfigurationController.java:204) [classes/:na]

  • #2
    How are you creating your transaction manager? and are you creating with name 'transactionManager'. If not, then you've to specify the name of your transaction manager while using @Transactional annotation.

    Comment

    Working...
    X