Question

I am using Spring 3.0.3, MyBatis 3.0.2 and mybatis-spring 1.0.0 on Apache Tomcat 6.0.29.

I have used declarative transactions of spring for transaction management. The issue is that the transactions are not working for me. The transaction only works once and thereafter nothing.

I have tried checking all my configs but no clue. Any pointers?

My configurations looks like this -

    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:pointcut id="dtxops"
            expression="execution(* com.service.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="dtxops" />
    </aop:config>

EDIT after comment -------------

I start the server and execute some transactional functionality and some times it works and some times it does not. Sometimes it keeps on working for 5-6 times and then suddenly it stops.

TX Manager and DS config -

<bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="resourceRef" value="true" />
        <property name="jndiName" value="java:comp/env/jdbc/MyDBInstance" />
    </bean>
Was it helpful?

Solution

Have you configured you datasource in Spring or Tomcat? (Tomcat has some weird default setting that auto commits after every statement which I guess makes it hard to run a DataSourceTransactionManager on top)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top