【发布时间】:2010-07-26 12:51:52
【问题描述】:
@Stateless @LocalBean
public class MySLSB {
@Resource
SessionContext ctx;
@PersistenceContext(unitName = "myPU")
EntityManager em;
public void T1() {
em.persist(new MyEntity(1L)); //T1 created!
/* wrong call to plain java object
T2();
*/
//corrected by lookup its business object first
ctx.getBusinessObject(MySLSB.class).T2();
ctx.setRollbackOnly();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void T2() {
em.persist(new MyEntity(2L)); //T2 created!
}
}
客户端调用T1(),首先T2作为一个新的事务应该被提交, 但 T1 会回滚。
预期结果:
T1:插入到myentity set id=1;
T2:插入到myentity set id=2;
T2:提交;
T1:回滚;
-> 在 DB 中创建 id=2 的行。
实际结果:
插入到myentity set id=1;
插入到myentity set id=2;
回滚;
-> 数据库中没有创建任何内容。
有什么问题?非常感谢!
【问题讨论】:
标签: jakarta-ee transactions ejb-3.0