Announcement Announcement Module
Collapse
No announcement yet.
Transaction rolled back because it has been marked as rollback-only Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction rolled back because it has been marked as rollback-only

    Below is the transaction configuration in my application context xml. i would like to use both annotation-driven and aop:config together for transaction management. I am getting following error when both are used together. if i use <tx:annotation-driven... alone its working fine...any suggession.

    <bean id="txManager" class="org.springframework.orm.hibernate4.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <tx:annotation-driven transaction-manager="txManager" order="200"/>

    <tx:advice id="txAdvice" transaction-manager="txManager">
    <!-- the transactional semantics... -->
    <tx:attributes>
    <!-- all methods starting with 'get' are read-only -->
    <tx:method name="search*, load*, read*, retrieve*, get*, find*, page*" read-only="true"/>
    <!-- other methods use the default transaction settings (see below) -->
    <tx:method name="*"/>
    </tx:attributes>
    </tx:advice>


    <aop:config proxy-target-class="false">
    <aop:advisor pointcut="execution(* *..*Service.*(..))" advice-ref="txAdvice" order="1"/>
    </aop:config>


    This is the stack trace when using above config together..

    org.springframework.transaction.UnexpectedRollback Exception: Transaction rolled back because it has been marked as rollback-only
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:717)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:318)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at com.tnets.tc.common.exceptioninterceptor.Exception Interceptor.invoke(ExceptionInterceptor.java:11)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy25.commit(Unknown Source)
    at org.springframework.test.AbstractTransactionalSpri ngContextTests.endTransaction(AbstractTransactiona lSpringContextTests.java:293)
    at org.springframework.test.AbstractTransactionalSpri ngContextTests.onTearDown(AbstractTransactionalSpr ingContextTests.java:233)
    at org.springframework.test.AbstractSingleSpringConte xtTests.tearDown(AbstractSingleSpringContextTests. java:125)
    at junit.framework.TestCase.runBare(TestCase.java:130 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit 3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)

  • #2
    Don't mix up transaction strategies. Choose between the tx:annotation-driven OR the tx:advice but not both because this leads to proxies of proxies and unexpected behaviour. I suggest using only tx:annotation-driven so that you can selectively choose which methods are to be read-only in your daos, by using the specific @Transactional annotation parameter. Read the reference guide.

    Comment


    • #3
      Thanks for your suggession.

      Comment

      Working...
      X