內交易方法是否有可能有狀態EJB本身內調用一個事務性方法?說得更清楚:調用相同的SFSB
@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:非法折返訪問:嘗試 做出對方法「公共無效 com.test.MyService.save()有狀態會話bean爲MyService迴環呼叫
SFSBs不支持內部呼叫嗎?
我正在運行Glassfish 3.1.1。
就可以解決這個執行下列操作:注入相同的服務在您的類像這樣@EJB私人的MyService自我;然後在myMethod()中調用保存方法,如self.save()。我已經在wildfly8中試過了。 – anna