Announcement Announcement Module
Collapse
No announcement yet.
tx:annotation-driven vs AnnotationTransactionAspect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tx:annotation-driven vs AnnotationTransactionAspect

    Hi all,

    I've run into a configuration subtlety when mixing @Configurable and @Transactional annotations. Consider a service with @Transactional annotations using a domain object annotated with @Configurable. If the applicationContext.xml contains the following:

    Code:
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    	<tx:annotation-driven transaction-manager="transactionManager" />
    	<aop:spring-configured />
    the following exception message is shown:

    Code:
    java.lang.IllegalStateException: Property 'transactionManager' must be set on transaction aspect
    	at org.springframework.util.Assert.state(Assert.java:353)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:261)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:219)
    	at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$before$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:64)
    	at com.gb1.tests.domaindi.UserServiceImpl.createUser(UserServiceImpl.java:13)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy19.createUser(Unknown Source)
    	at com.gb1.tests.domaindi.TransactionalEntityTest.testConfigurableWithTransactionalEntity(TransactionalEntityTest.java:14)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	at junit.framework.TestResult$1.protect(TestResult.java: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:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    However if I replace the tx:annotation-driven tag by this:

    Code:
    	<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect"
    		factory-method="aspectOf">
    		<property name="transactionManager" ref="transactionManager" />
    	</bean>
    everything runs fine.

    I thought that the tx:annotation-driven tag was simply a shortcut for the longer AnnotationTransactionAspect bean definition.

    Can someone explain this difference in behavior?

    Thanks a bunch!
Working...
X