Hi everybody,
I'm currrently working with Spring 2.0.6, Hibernate 3.2.2GA and MySQL Java Connector 5.0.4 and have problem with transaction.
It looks like MySQL doesn't take care of autocommit false setted by the transaction manager and directly persist change to my database, here is my config whether I'm in a transaction boundary or not :
I deploy my application on JBoss 4.0.5 using standard MySQL datasource (as specified in JBoss example).
<bean id="myDao" class="com.cdsolutionsinfo.test.MyDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="transactionAdvice" transaction-anager="transactionManager">
<tx:attributes>
<tx:method name="is*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aopointcut id="repositoryOperation"
expression="execution(* com.cdsolutionsinfo..*Dao.*(..))" />
<aop:advisor advice-ref="transactionAdvice"
pointcut-ref="repositoryOperation" />
</aop:config>
Now I have a reattach method in my dao to force to reattach element to active session that does following :
public void reattach(MyEntity entity) {
getHibernateTemplate().saveOrUpdate(entity)
}
I also have service layer using the daos, I also define transaction boundaries at this level and then service can make call to multiples dao's services and all dao calls participate in same transaction, I enable debug mode of TransactionManager and TransactionInterceptor, everything look good, except information is directly stored to database and rollbacking transaction doesn't work properly in my service.
public void myService(Entity myEntity) {
// begin to reattach domain object to avoid lazy load problem while
// working with object and children.
entityDao.reattach(myEntity);
// Do any business logic here, if something fail a RuntimeException is
// throwned to force to rollback transaction but too late information
// is already stored to database before giving control to caller method.
}


ointcut id="repositoryOperation"
Reply With Quote