我想记录参与事务的 EJB 方法的错误或成功。我应该把日志放在哪里?据我所知,交易将在我doSomething
完成后提交。因此,在该方法中,我无法确定提交是否成功。这就提出了这个问题。
public class MyEjb {
@Inject
AnotherEjb anotherEjb;
@Inject
LoggerEjb logger;
public void doSomeThing() {
MyBean b = getSomething();
anotherEjb.persistSg(b);
/* logger.log is transaction if of attrubute NOT_SUPPORTED to
ensure separation from caller transaction */
logger.log("Did something successfully.");
}
}
public class AnotherEjb {
@Inject
EntitiyManager em;
public void persistSg(MyBean entity) {
em.persist(entity);
}
}