Results 1 to 4 of 4

Thread: UnexpectedRollbackException on read-only method

  1. #1
    Join Date
    Jan 2008
    Posts
    248

    Default 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. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    248

    Default

    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

  4. #4
    Join Date
    May 2011
    Posts
    5

    Default Re:Default 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 : contact@attuneinfocom.com
    Liferay portlet Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •