All,
My app runs on JDK 1.5, Hibernate 3.0.5 and Spring 1.2.5
I've been unable to get the @Transactional attribute working.
The relevant part of my spring configuration is below:
My code looks like this:Code:<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="transactionInterceptor"/> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="txManager"/> <property name="transactionAttributeSource"> <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/> </property> </bean>
and the implementation is:Code:public interface MyCrudService { @Transactional public void create(MyObject object); }
The currentSession() method obtains a hibernate session that has it's flush mode set to AUTO. However, if I don't use the annotation, and instead use an implementation like the one below, my tests pass:Code:public class DefaultMyCrudService implements MyCrudService { public void create(MyObject object) { currentSession().save(object); } }
For my tests, I obtain the service from spring, so I'm sure that it will get advised correctly by the TransactionInterceptor.Code:public class DefaultMyCrudService implements MyCrudService { public void create(MyObject object) { Transaction transaction = currentSession().beginTransaction(); currentSession().save(object); transaction.commit(); } }
Am I doing something wrong here?


Reply With Quote