Announcement Announcement Module
Collapse
No announcement yet.
Nesting Transactions? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nesting Transactions?

    Hi.

    Need a little help trying to figure out how to nest transactions in spring... I am in the situation where I need to be able to commit a transaction in several stages. There are 3 stages total. Call it create update1 and update2. I currently have a single transaction wrapped around my service layer. The problem is that the method must make multiple updates to the same stored object so when the 2nd update attempts, the read is blocked because changes are pending commit.

    I have tried adding a second set of TX advice for methods called by the service layer as such:

    Code:
    	<!-- Transaction Configurations -->
    	<tx:advice id="dsTxAdvice" transaction-manager="directoryTransactionManager">
    		<tx:attributes>			
    			<tx:method name="createAccount" />
    			<tx:method name="migrateAccount" propagation="REQUIRES_NEW" isolation="READ_UNCOMMITTED"/>
    			<tx:method name="*" propagation="REQUIRES_NEW" read-only="true" />
    		</tx:attributes>
    	</tx:advice>
    	
    	<tx:advice id="mapperTxAdvice" transaction-manager="directoryTransactionManager">
    		<tx:attributes>
    			<!-- Service Routines -->
    			<tx:method name="insert" />
    			<tx:method name="update" />
    			<tx:method name="delete" />
    			<tx:method name="*" read-only="true" />
    		</tx:attributes>
    	</tx:advice>
    	
    	<aop:config>
    		<aop:pointcut id="DirectoryServicesTxAdvice" expression="execution(* com.company.domain.directory.service.DirectoryServices.*(..))" />
    		<aop:pointcut id="EntityMapperTxAdvice" expression="execution(* com.company.domain.directory.mapper.*.*(..))" />
    		<aop:advisor advice-ref="dsTxAdvice" pointcut-ref="DirectoryServicesTxAdvice" />
    		<aop:advisor advice-ref="mapperTxAdvice" pointcut-ref="EntityMapperTxAdvice" />
    	</aop:config>
    but this only results in the following exception:

    Code:
    2009-03-03 18:23:55,790 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Creating new transaction with name [com.comcast.domain.directory.service.DirectoryServices.searchAccounts]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly
    2009-03-03 18:23:55,836 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Creating new transaction with name [com.comcast.domain.directory.mapper.EntityMapperTemplate.search]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
    2009-03-03 18:23:56,008 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Initiating transaction commit
    2009-03-03 18:23:56,008 [main] DEBUG com.comcast.structural.transaction.compensating.support.CustomCompensatingTransactionOperationManager  Performing commit
    2009-03-03 18:23:56,008 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Resuming suspended transaction
    2009-03-03 18:23:56,008 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Creating new transaction with name [com.comcast.domain.directory.mapper.EntityMapperTemplate.find]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
    2009-03-03 18:23:56,055 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Initiating transaction commit
    2009-03-03 18:23:56,055 [main] DEBUG com.comcast.structural.transaction.compensating.support.CustomCompensatingTransactionOperationManager  Performing commit
    2009-03-03 18:23:56,055 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Resuming suspended transaction
    2009-03-03 18:23:56,055 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Creating new transaction with name [com.comcast.domain.directory.mapper.EntityMapperTemplate.find]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
    2009-03-03 18:23:56,118 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Initiating transaction commit
    2009-03-03 18:23:56,118 [main] DEBUG com.comcast.structural.transaction.compensating.support.CustomCompensatingTransactionOperationManager  Performing commit
    2009-03-03 18:23:56,118 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Resuming suspended transaction
    2009-03-03 18:23:56,118 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Initiating transaction commit
    2009-03-03 18:23:56,118 [main] DEBUG com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Initiating transaction rollback after commit exception
    java.lang.NullPointerException
    	at org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCommit(AbstractCompensatingTransactionManagerDelegate.java:102)
    	at com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager.doCommit(CustomContextSourceTransactionManager.java:52)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy13.searchAccounts(Unknown Source)
    	at com.comcast.test.Test.main(Test.java:33)
    2009-03-03 18:23:56,118 [main] ERROR com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager  Commit exception overridden by rollback exception
    java.lang.NullPointerException
    	at org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCommit(AbstractCompensatingTransactionManagerDelegate.java:102)
    	at com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager.doCommit(CustomContextSourceTransactionManager.java:52)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy13.searchAccounts(Unknown Source)
    	at com.comcast.test.Test.main(Test.java:33)
    Exception in thread "main" java.lang.IllegalStateException: No value for key [[email protected]b] bound to thread [main]
    	at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:202)
    	at org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCleanupAfterCompletion(AbstractCompensatingTransactionManagerDelegate.java:122)
    	at com.comcast.structural.ldap.transaction.compensating.manager.CustomContextSourceTransactionManager.doCleanupAfterCompletion(CustomContextSourceTransactionManager.java:43)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:989)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:782)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy13.searchAccounts(Unknown Source)
    	at com.comcast.test.Test.main(Test.java:33)
    Can anyone give me some advise as to where I am going wrong? Is this possible through an XML config or do I need to use programmatic demarcation?

    Thanks.

    Keith

  • #2
    Nested transactions are not supported by the LDAP compensating transaction support.

    Comment


    • #3
      Well... that would explain my troubles.

      Thanks.

      Keith

      Comment


      • #4
        Any idea about how to manage this situation. I am also facing the same kind of issue.

        Comment

        Working...
        X