I have a project in which I am using spring and persistence. I am managing @Transactional
, but there is an external project which is going to be used for common operations in the database and I am sending the entityManager
with which I am executing the operations of my DAOs, when an error occurs at the end of the method that executes all operations, the expected result is that the transactions rollback, but the transaction in my external project does not execute rollback.
How can I get the rollback to run on the entire service when an error occurs.
Example
DAO:
@Repository
public class MyDAO{
@PersistenceContext(unitName = "PORTALPU")
protected EntityManager entityManager;
@Autowired
private externalProjectDAO externalProjectDAO;
public void save(Object obj){
entityManager.persist(obj);
//Some other persist action in external DAO
externalProjectDAO(entityManager,obj);
int i=10/0; //Here the entityManager must make a rollback
}
}
Service:
@Transactional
public class ServiceClass{
@Autowired
private MyDAO myDao;
public void save(Object obj){
myDAO.save(obj);
}
}