ok, enough. I couldn't make this work. I am a newbie to Spring transactions and using the @Transactional annotation in my service to manage transactions. Below is my spring bean configuration file.
<?xml version="1.0"开发者_C百科 encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myapp"/>
<!-- other <bean/> definitions here -->
</beans>
and I annotate my service:
@Transactional
public class MyServiceImpl implements MyService {
...
}
I notice two things
- The connection that I get in my DAO [using DataSourceUtils.getConnection(dsName)] has the autocommit enabled [true].
- As far as I debugged there doesn't look to be any transaction that has begun during my service method invocation.
Anyone had this problem?
I use Hibernate with the HibernateTransactionManager myself, so I'm not too familiar with how the JDBC transaction manager works. Have you inspected the callstack to see whether or not TransactionInterceptor is in there ? If it is, then the transactional annotation is working, and you may just be missing something else. If you haven't looked for it, what makes you think that it's not working ? To eliminate the obvious, have you explicitly set a setting in your JDBC configuration to disable autocommit ?
精彩评论