Announcement Announcement Module
Collapse
No announcement yet.
UnexpectedRollbackException on read-only method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • UnexpectedRollbackException on read-only method

    Hi,

    I'm getting org.springframework.transaction.UnexpectedRollback Exception: Transaction rolled back because it has been marked as rollback-only after an org.springframework.orm.ObjectRetrievalFailureExce ption occurs.

    PHP Code:
    org.springframework.orm.ObjectRetrievalFailureExceptionObject of class [nl.project.model.Itemwith identifier [9]: not found


    org
    .springframework.transaction.UnexpectedRollbackExceptionTransaction rolled back because it has been marked as rollback-only
        at org
    .springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:717)
        
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
        
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
        
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
        
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        
    at $Proxy156.getSearchFacetOffers(Unknown Source
    The thing is, the transaction is marked as read-only through

    PHP Code:
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <
    tx:attributes>
            <
    tx:method name="get*" read-only="true"/>
            <
    tx:method name="*" />
        </
    tx:attributes>
    </
    tx:advice
    I don't understand why I should get a rollbackexception on a read-only method? So, I got this problem to go away by setting up like so

    PHP Code:
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <
    tx:attributes>
            <
    tx:method name="get*" read-only="true" no-rollback-for="org.springframework.orm.ObjectRetrievalFailureException"/>
            <
    tx:method name="*" />
        </
    tx:attributes>
    </
    tx:advice
    But I'm not really sure if this is "right". Is there any good reason why a read-only transaction should trigger a rollback? Shouldn't I just set no-rollback-for any kind of Exception?

    Kind regards,

    Marc

  • #2
    Is your object that you are retrieving correctly mapped? I wonder if your mapping is generating invalid SQL that the database is throwing out?

    I would suggest looking at logging/profiling on your db to see what it is doing. My guess is that you will see so bad SQL/timeouts etc. executing.

    Comment


    • #3
      No, I'm sure that is not it. The issue is that a call is made to a get function based on a non-existing id

      Comment


      • #4
        Reefault UnexpectedRollbackException on read-only method

        Hi,
        Transaction rolled back because of,

        Spring's transaction manager ends up catching the checked exception and tries to commit the transaction, unaware of the nested runtime exception that method threw. Once I discovered this, I set up the transaction wrapper to rollback for checked exceptions as well, now it works as expected.


        Regards
        Kevin Thomas
        Attune Infocom Inc
        http://www.attuneinfocom.com
        Email : [email protected]
        Liferay portlet Development

        Comment

        Working...
        X