Hello!
I'm new to using Spring/Hibernate, so I thank you in advance for your patience =)
I'm trying to use Spring's transaction management with Hibernate, but when I deploy my Spring / Hibernate app to Tomcat and then throw an exception from within the code, no rollback is occuring. Here's a snippet from my Spring applicationContext.xml file:
And here is an example of how I'm trying to use this:Code:<!-- Deposit Manager Beans --> <bean id="depositManager" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"><value>org.dm.daniel.grace.business.DepositManager</value></property> <property name="interceptorNames"> <list> <!-- <idref local="depositManagerSecurity"/> --> <idref local="transactionInterceptor"/> <idref local="depositManagerTarget"/> </list> </property> </bean> <bean id="depositManagerTarget" class="org.dm.daniel.grace.business.DepositManagerImpl"> <property name="sessionFactory"><ref local="sessionFactory"/></property> <property name="logManager"><ref local="logManager"/></property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"><ref bean="transactionManager"/></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean>
This is essentially supposed to create a deposit in the database on the call to saveOrUpdate(), but then "crash" and rollback. It crashes, but no rollback occurs and the new deposit remains in the database.Code:public DepositDTO create(DepositDTO dto) { // Create a new deposit based on DepositDTO info Deposit deposit = DTOFactory.getDeposit(dto); // "Ignore" the id field - make it null deposit.setId(null); // Save the new deposit getHibernateTemplate().saveOrUpdate(deposit); if (0 < 1) throw new RuntimeException("Should cause rollback of new deposit"); // Populate newDTO DepositDTO newDTO = DTOFactory.getDepositDTO(deposit); // * * Logging * * String logMsg = "Deposit [" + newDTO.getId() + "] Created new deposit: " + newDTO; // Write to system log logger.info(logMsg); return newDTO; }
For reference, I'm using Hibernate 2.1, MySQL Connector/J 3.1.6, and MySQL server 4.0.23.
Thanks for any help!!
~Tom


Reply With Quote
Check 