I am trying to insert rows into two different tables. Can any one please tell me why if an insertion into one table fails, the insertion into another table is not getting rollbacked in Hibernate. My sources are:
Spring Bean Loader
<?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="txnManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!--Data Source Properties -->
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>Common.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
</bean>
<bean id="manager" class="src.Manager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="myObject" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txnManager" />
<property name="target" ref="manager" />
<property name="transactionAttributes" >
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
Manager.java
package src;
import java.util.ArrayList;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class Manager extends HibernateDaoSupport {
public void storeValue(ArrayList al, ArrayList al1) {
try {
System.out.println("In storeValue");
SynSeqNumVO oSynSeqNumVO = (SynSeqNumVO) al.get(0);
SynProdTypeVO oSynProdTypeVO = (SynProdTypeVO) al1.get(0);
getHibernateTemplate().save(oSynSeqNumVO);
getHibernateTemplate().save(oSynProdTypeVO);
System.out.println("Saved the Values");
}
catch (Exception e) {
System.out.println("Exception in storValue : "+e);
}
}
}
|