I'm using @Trasactional in one service class and inside that calling multiple update method. if i have any error in update any one method means all updated process want to rollback. how to handle this?
my service class is
@Service
@Transactional(rollbackFor = Exception.class)
public class empSaveImpl implements empSave{
@Autowired
private EmpDaoConvert empDaoConvert;
public void empSaveOrUpdate() throws Exception{
try {
String status = empDaoConvert.empSaveOrUpdate();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
my EmpDaoConvert class is
@Component
public class EmpDaoConvert throws Exception {
@Autowired
private EmpDao empDao;
public String empSaveOrUpdate() throws Exception{
String ejb_up = empDao.saveejb_up("Y"); //ejb
String jdbc_up = empDao.savejdbc_up('Y'); //jdbc
String hyp_up = empDao.savehyp_up("Y"); //hyb
return "success";
}
}
Dao class is
@Repository
public class EmpDao{
@Autowired
SessionFactory sessionFactory;
public String saveejb_up(String test) throws Exception{
..... some update process using EJB connection.......
}
public String savejdbc_up(char test) throws Exception{
.......some update process using JDBC template.......
}
public String savehyp_up(String test){
SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery("update empProfile set morning_shift= '"+test+"' where emp_id = 658954");
query.executeUpdate(); //hibernate update
return "success";
}
}
Transaction manager
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>