Announcement Announcement Module
No announcement yet.
Transaction management Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction management

    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
    HTML Code:
    [B]delaying identity-insert due to no transaction in progress[/B]
    Here is classes and configuration:

    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" />
    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 class="org.springframework.orm.jpa.JpaTransactionManager"
    	<property name="entityManagerFactory" ref="entityManagerFactory" />
    <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
    	<property name="persistenceUnitName" value="persistenceUnit" />
    	<property name="dataSource" ref="dataSource" />
    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:
    <Context path="/cmcloud">
    		loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" />
    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)
    public class ServiceImpl<T> implements Service<T> {
    	public T save(T entity) {
    Note that this class IS NOT in the main project package, but in an external one (a simple class library).
    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.


  • #2
    I think, your ServiceImpl is not under the package(s) you specified in <context:component-scan>. Note that you can have comma seperated different packages in here as well. What say?


    • #3
      Thank you for the reply.
      I found the error and forgot to post the solution.

      The error was in the aspectj-maven-plugin: I didn't specify the <weaveDependencies /> option, thus the transaction aspect wasn't weaved also to the external jars.

      Hope this can help other developers.

      Best regards,