我不确定这是否正确,但我需要在事务回滚后,我的对象返回其初始状态。我创建了一个junit测试,但它失败了。
try {
entityManager.getTransaction().begin();
entityManager.persist(itemBec);
// throw new Exception("teste");
// throw new EJBTransactionRolledbackException("teste");
// throw new ConstraintViolationException("teste", null, null);
throw new RuntimeException("teste");
} catch (Exception e) {
entityManager.getTransaction().rollback();
} finally {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().commit();
}
}
entityManager.close();
factory.close();
Assert.assertNull(itemBec.getId());
我是否错误地假设对象必须返回其初始状态?
谢谢。