PFB我的代码,
try {
entityManager = emFactory.createEntityManager();
emTransaction = entityManager.getTransaction();
emTransaction.begin();
EmployeeEntity e1 = new EmployeeEntity();
e1.setEmpId(1);
e1.setEmpName("Dheepan");
EmployeeEntity e2 = new EmployeeEntity();
e2.setEmpName("Raju");
entityManager.persist(e1);
entityManager.persist(e2);
emTransaction.commit();
}catch(PersistenceException e){
if(emTransaction!=null && emTransaction.isActive()){
emTransaction.rollback();
}
}
未故意在e2中设置empId属性,以便抛出异常。一旦抛出异常,就应该发生回滚。但我仍然可以看到e1被持久存入数据库。有谁能说出为什么回滚没有发生?