Hi all,
I saw all the threads related to transaction not rolling back, but could not relate anyone to my situation. Or so I think![]()
This is my applicationContext.xml section ===
<bean id="tagDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://ashah/dwhweb</value>
</property>
<property name="username">
<value>dwhweb</value>
</property>
<property name="password">
<value>dwhweb</value>
</property>
</bean>
<bean id="tagSessionFactory"
class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
<property name="mappingResources">
<list>
<value>
com/tagaudit/tagportal/om/SecurityPrincipal.hbm.xml
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="dataSource">
<ref bean="tagDataSource"/>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="tagTransactionManager"
class="org.springframework.orm.hibernate.Hibernate TransactionManager">
<property name="sessionFactory">
<ref local="tagSessionFactory"/>
</property>
</bean>
<!-- ============== End Data Access using Spring provided O/R Mappers ============== -->
<bean id="securityPrincipalDao"
class="com.tagaudit.tagportal.om.SecurityPrincipal Dao">
<property name="sessionFactory">
<ref bean="tagSessionFactory"/>
</property>
</bean>
<bean id="testServiceTarget"
class="com.tagaudit.tagportal.services.TestService Impl">
<property name="securityPrincipalDao">
<ref bean="securityPrincipalDao"/>
</property>
</bean>
<bean id="testService"
class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="tagTransactionManager"/>
</property>
<property name="target">
<ref bean="testServiceTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="testMethodRead">PROPAGATION_REQUIRED,readOnly </prop>
<prop key="testMethodWrite">
PROPAGATION_REQUIRED,-DataAccessException</prop>
</props>
</property>
</bean>
And following is my file ======
public void testMethodWrite() throws TagException {
SecurityPrincipal principal = new SecurityPrincipal();
principal.setClassname("TestClass");
principal.setCreationDate(Calendar.getInstance().g etTime());
principal.setFullPath("testDelete");
principal.setPrincipalId(new Integer(500));
for(int i = 0; i < 4; ++i) {
try {
securityPrincipalDao.savePrincipal(principal);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Did the insert too !!!!");
}
When I call this method, it performs the first write, and then throws exception, but never rolls back. Please help :cry:


Reply With Quote