Complete transaction with multiple dao in service class
How do I achieve a complete transaction where a service class requires
more than one data access object. Assuming I have the following structure.
Currently, if my dao2 failed, the dao1 still being committed to the
database which I do not want it to happen. However, I need my dao to be
reusable.
public class mainService(){
dao1.store(obj1);
dao2.store(obj2);
}
And my dao is written in this way.
Dao 1
private EntityManager entityManager;
@Transactional
public void store(Object obj1){
entityManager.persist(obj1);
}
Dao 2
private EntityManager entityManager;
@Transactional
public void store(Object obj2){
entityManager.persist(obj2);
}
Please help.
No comments:
Post a Comment