Hi,
I am facing problem in transaction rollback using @Transactional annotation
I have following method in service class
If any exception occurs in second method createOrder(), all transaction should rollback but it is not happening. Can any body tell me the problem.
If I remove @Transactional annotation all from JpaDaoImpl.java then rollback is working fine. JpaDaoImpl.java is written in the initial development and we dont want to change it as it is used in many classes.
I am facing problem in transaction rollback using @Transactional annotation
I have following method in service class
Code:
public class ItemServices {
public void saveUpdate(){
try {
executeTransaction();
}catch(Exception e){
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void executeTransaction(){
deleteItem();
createOrder();
}
}
private void deleteItem() {
JpaDaoImpl.remove();//logically delete
JpaDaoImpl.update();//update status
}
private void createOrder() {
JpaDaoImpl.persist();
JpaDaoImpl.update();//update status
}
public class JpaDaoImpl implements JpaDao {
@Transactional(readOnly = true)
public persist(Object object) {
getEm().persist(object);
}
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void update(Object object) {
getEm().merge(object);
}
@Transactional(readOnly = true)
public void remove(Object object) {
getEm().remove(object);
}
}
If any exception occurs in second method createOrder(), all transaction should rollback but it is not happening. Can any body tell me the problem.
If I remove @Transactional annotation all from JpaDaoImpl.java then rollback is working fine. JpaDaoImpl.java is written in the initial development and we dont want to change it as it is used in many classes.