Hi!
I'm very new to Spring and Hibernate. I'm trying span a transaction against 2 DAO calls from my facade method call. I set up declarative transactionality through the applicationContext.xml using the TransactionProxyFactoryBean as detailed in the Spring documentation. To test rollback, I insert data through the first DAO method call then throw a RuntimeException before the second DAO method call is made. I expect the data inserted from the first DAO call to be rolled back. This is not the case and the inserted data lives on in the db.
SiteImpl class (facade)
AccountDao.newAccount(account)Code:public void insertUser(Account account, Address address, Phone phone){ this.accountDao.newAccount(account); address.setAccountid( account.getId() ); phone.setAccountid( account.getId() ); this.addressDao.newAddress(address); this.phoneDao.newPhone(phone); }
AddressDao.newAddress(address)Code:public void newAccount(Account account) throws DataAccessException { account = (Account)getHibernateTemplate().saveOrUpdateCopy(account); throw new DataAccessResourceFailureException("testing"); }
applicationContext.xmlCode:public void newAddress(Address address) throws DataAccessException { address = (Address)getHibernateTemplate().saveOrUpdateCopy(address); }
Please Help!!Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>@db.driver@</value> </property> <property name="url"> <value>@db.url@</value> </property> <property name="username"> <value>@db.user@</value> </property> <property name="password"> <value>@db.pw@</value> </property> </bean> <bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>site.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="dataSource"> <ref bean="myDataSource"/> </property> </bean> <bean id="myTransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="mySessionFactory"/> </property> </bean> <bean id="mySiteService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="myTransactionManager"/> </property> <property name="target"> <ref bean="siteTarget"/> </property> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="retrieve*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <!-- ========================= BUSINESS OBJECT DEFINITIONS ======================== --> <bean id="accountDao" class="com.site.dao.hibernate.AccountDaoImpl"> <property name="sessionFactory"><ref bean="mySessionFactory"/></property> </bean> <bean id="addressDao" class="com.site.dao.hibernate.AddressDaoImpl"> <property name="sessionFactory"><ref bean="mySessionFactory"/></property> </bean> <bean id="phoneDao" class="com.site.dao.hibernate.PhoneDaoImpl"> <property name="sessionFactory"><ref bean="mySessionFactory"/></property> </bean> <bean id="siteTarget" class="com.site.domain.logic.SiteImpl"> <property name="accountDao"><ref bean="accountDao"/></property> <property name="addressDao"><ref bean="addressDao"/></property> <property name="phoneDao"><ref bean="phoneDao"/></property> </bean> <!-- ========================= REMOTE EXPORTER DEFINITIONS ======================== --> </beans>
Thanks!
Don


Reply With Quote