【发布时间】:2017-09-14 00:28:50
【问题描述】:
我使用带有@scheduled 注释的EJB 每10 秒循环一次我的所有上下文实体。所有 Contexts 实体彼此无关,因此应为其更新方法创建新事务:
@Stateless
public class UpdateService {
@EJB
ContextDao contextDao;
@Schedule(second = "*/10", minute = "*", hour = "*")
public void update() {
for(ContextEntity context : contextDao.findAllContexts()) {
updateContext(context);
}
}
public void updateContext(ContextEntity context) {
// load data from db
// update some stuff
// save back to db
}
}
现在我想为 updateContext 方法创建一个事务。因此,如果我在一个 ContextEntity 中遇到任何错误,则只有该事务应该回滚,而不是整个循环。
- update 和 updateContext 的正确 TransactionAttributes 是什么?
- 是否必须为 updateContext 方法使用不同的 EJB?
谢谢
【问题讨论】:
-
这是一个很好且有用的描述,但我不会找到它。我会寻找 nested 或 embedded 调用 same EJB 或其他东西。或许可以改名
标签: jakarta-ee transactions ejb scheduled-tasks