我在無狀態EJB使用2 PU和他們每個人的調用一個方法:如何防止「本地事務已有1個非XA資源」異常?
@PersistenceContext(unitName="PU")
private EntityManager em;
@PersistenceContext(unitName="PU2")
private EntityManager em2;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void getCandidates(final Integer eventId) throws ControllerException {
ElectionEvent electionEvent = em.find(ElectionEvent.class, eventId);
...
Person person = getPerson(candidate.getLogin());
...
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Person getPerson(String login) throws ControllerException {
Person person = em2.find(Person.class, login);
return person;
}
這些方法與REQUIRES_NEW transcaction註解,以避免此異常。當我從javaFX applet調用這些方法時,所有方法都按預期工作。現在我試圖從JAX-RS webservice中調用它們(我沒有看到任何邏輯上的差異,因爲在這兩種情況下,ejb都是在初始上下文中查找的),並且我不斷收到此異常。當我在glassfish 2.1連接池中設置XADatasource時,em2上出現空指針異常。
任何想法接下來要嘗試什麼?
的問候,我在無狀態EJB使用2 PU
另請參閱http://stackoverflow.com/questions/2413911/if-i-access-usertransaction-does-this-mean-that-i-use-2-phase-commit-or-xa/2425585#2425585 – ewernli 2010-04-22 06:27:09