Hi everybody,
I'm having problem managing transactions with @Transactional annotaton and AspectJ.
Other annotations such as @Configurable work as expected. Also auto-wiring dependencies is ok.
I can't persist any entity because
Here is classes and configuration:HTML Code:[B]delaying identity-insert due to no transaction in progress[/B]
HTML Code:<context:spring-configured /> <context:load-time-weaver /> <!-- packages containing all the beans I need. They are correct because @Component, @Configurable and @Autowired work as expected --> <context:component-scan base-package="x.y.z" /> .....This is the context.xml placed under META-INF/ (I'm using Tomcat7). I also added spring-instrument-tomcat to my CATALINA/lib folder.HTML Code:<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> <property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.username}" /> <property name="password" value="${database.password}" /> <property name="testOnBorrow" value="true" /> <property name="testOnReturn" value="true" /> <property name="testWhileIdle" value="true" /> <property name="timeBetweenEvictionRunsMillis" value="1800000" /> <property name="numTestsPerEvictionRun" value="3" /> <property name="minEvictableIdleTimeMillis" value="1800000" /> <property name="validationQuery" value="SELECT 1" /> </bean> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" /> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="persistenceUnitName" value="persistenceUnit" /> <property name="dataSource" ref="dataSource" /> </bean>
This is the class that should be weaved to provide transaction support (this class is generic, it is specialized for every entity I need to manage)HTML Code:<Context path="/cmcloud"> <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" /> </Context>
Note that this class IS NOT in the main project package, but in an external one (a simple class library).Code:@Service @Configurable public class ServiceImpl<T> implements Service<T> { @Override @Transactional public T save(T entity) { .... } }
If I subclass it in the main project package and override the transactional methods, transactions work as expected.
It is likely that I missed something in the configuration as this is the first time I'm using AspectJ but can't figure out what.
Thanks,
Stefano


Reply With Quote
