Java JPA的逻辑提交
我要两张桌子。ActionLog&QueueLog表,当用户执行任何操作时,我将插入操作表并更新队列表中的少数记录 现在,当用户执行任何操作时,只有操作表被插入,队列表没有得到更新&我在日志中没有看到任何异常或错误。我希望添加逻辑提交,如果其中任何一个操作失败(第33行和第43行),则应回滚所有操作,意味着它不应该在任何表上插入或更新Java JPA的逻辑提交,java,jpa,entitymanager,Java,Jpa,Entitymanager,我要两张桌子。ActionLog&QueueLog表,当用户执行任何操作时,我将插入操作表并更新队列表中的少数记录 现在,当用户执行任何操作时,只有操作表被插入,队列表没有得到更新&我在日志中没有看到任何异常或错误。我希望添加逻辑提交,如果其中任何一个操作失败(第33行和第43行),则应回滚所有操作,意味着它不应该在任何表上插入或更新 EntityManager entityManager = null; entityManager = EntityManagerUtil.get
EntityManager entityManager = null;
entityManager = EntityManagerUtil.getEntityManager();
Boolean isdone = false;
try {
ActionLog actionLog = new ActionLog();
TbBamiActionLogPK actionLogPk = new TbBamiActionLogPK();
entityManager.getTransaction().begin();
QueueLog QueueLog = entityManager.find(QueueLog.class, refNo,
LockModeType.PESSIMISTIC_WRITE);
actionLogPk.setRefno(refNo);
Integer currVerStr = Integer.valueOf(QueueLog.getCurrVersion().toString());
Integer currVer = currVerStr + 1;
LOG.info("AR-VERSION currVerStr" + currVerStr);
LOG.info("AR-VERSION currVer" + currVer);
actionLogPk.setVersion(currVer);
actionLog.setId(actionLogPk);
actionLog.setAction(action);
actionLog.setPrevAssignee(assignedTo);
actionLog.setPrevAssgneeRole(assignedToRole);
actionLog.setAssignee(assignedTo);
actionLog.setAssigneeRole(assignedToRole);
actionLog.setComments(comments);
actionLog.setEntryDateTime(new Timestamp(System.currentTimeMillis()));
// Adding Action Log
entityManager.persist(actionLog);//line 33
LOG.debug("Inseted into action log");
// Updating Queue Log
QueueLog.setAction(action);
QueueLog.setStatus("CLOSED");
LOG.debug("Updating status as closed");
QueueLog.setExitDateTime(new Timestamp(System.currentTimeMillis()));
QueueLog.setCurrVersion(BigDecimal.valueOf(currVer));
entityManager.merge(QueueLog);//line 43
LOG.debug("Going to do commit");
entityManager.getTransaction().commit();
LOG.debug("Commited..");
isdone = true;
} catch (Exception e) {
isdone = false;
//entityManager.lock(QueueLog.class, LockModeType.NONE);
LOG.error("ERR_MSG", e);
} finally {
// entityManager.lock(QueueLog.class, LockModeType.NONE);
entityManager.close();
}
return isdone;
您的问题是什么?请阅读我的描述,我想添加逻辑提交。如果任何一个失败,所有内容都应回滚。我们有相应的事务是的,这是一个常见的事务,用于回滚
catch
子句中的事务。。。我遗漏了什么吗?你的问题是什么?请阅读我的描述,我想添加逻辑提交。如果任何一个失败,所有内容都应该回滚,我们有相应的事务是的,这是一个常见的事务,在catch
子句中回滚事务。。。我错过什么了吗?