@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將被回滾。EJB CMT TransactionAttributeType.REQUIRES_NEW不起作用
預期結果:
T1:插入myEntity所組ID = 1; T2:insert into myentity set id = 2;
T2:commit;
T1:回滾;
- >在數據庫中創建id = 2的行。
實際結果:
insert into myentity set id = 1;
insert into myentity set id = 2;
rollback;
- >在數據庫中沒有創建任何內容。
什麼問題?非常感謝!