是否可以从有状态 EJB 本身调用事务方法?说得更清楚:
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Stateless
public class MyService {
@Resource
SessionContext ctx;
public void myMethod() {
// do something...
// invoke method from the same class
// As expected - this doesn't work as it's a regular local-call,
// it's not aware of EJB nature of this call.
save();
// Doesn't work (although it worked with SLSB)
ctx.getBusinessObject(MyService.class).save();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void save() {
// do something...
}
}
现在我想要实现的是让用户调用 myMethod(); 我想确保在没有 JTA 事务的情况下执行此方法。在这个电话之后,我想调用一个 save(); 将在事务中运行的方法。
如果我使用 ctx.getBusinessObject(-) 方法,我会得到:
警告:在调用 EJB MyService 方法时发生系统异常 public void com.test.MyService.save() javax.ejb.IllegalLoopbackException: Illegal Reentrant Access : Attempt to make a loopback call on method 'public void com.test.MyService .save() 用于有状态会话 bean MyService
SFSB 不支持内部调用吗?
I'm running Glassfish 3.1.1.