@Override
@Transactional(rollbackFor = { RuntimeException.class, Exception.class}, propagation = Propagation.REQUIRED)
public String upload(ObjectVO vo) throws CustomException {
.......
}
In this service, I am inserting in to two tables. If there is an Exception while processing data (like mandatory field check) for the second table which supposed to get inserted after the first table, should it roll back the data inserted in the first table in the same transaction? In my case I am not getting it rolledback. What is the expected behaviour? (And yes, I am not catching the exception, its a custom exception which is included in rollbackFor
clause, and is being thrown)
(I am using hibernate
)
The DAO Layer does getSession().save(entity);
(getSession()
returns currentSession)
(So the data in the first table remains)
The tables are not related.
<tx:annotation-driven/>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>