如何防止“本地交易已经有1个非XA资源”例外? [英] How to prevent "Local transaction already has 1 non-XA Resource" exception?

查看:163
本文介绍了如何防止“本地交易已经有1个非XA资源”例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在无状态EJB中使用2个PU,并且在一个方法上调用它们:

I'm using 2 PU in stateless EJB and each of them is invoked on one method:

@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上得到了nullpointer异常。

Those methods are annotated with REQUIRES_NEW transcaction to avoid this exception. When I was calling these method from javaFX applet, all worked as expected. Now I'm trying to call them from JAX-RS webservice (I don't see any logical difference as in both cases ejb was looked up in initial context) and I keep getting this exception. When I set up XADatasource in glassfish 2.1 connection pools, I got nullpointer exception on em2.

任何想法接下来要尝试什么?

Any ideas what to try next?

问候

推荐答案

好的,

它已经解决了现在。我将分享以防万一有人被类似的事情处理。
整个问题在于netbeans部署。它们会覆盖glassfish连接池中的设置,当你在运行时正确设置它们时,你会得到npe或缺少密码的傻东西。编辑它的地方是 sun-resources.xml 。 XML元素具有datasource-classname和rs-type属性。在Derby数据库中需要做的是:

it's solved now. I'll share just in case somebody got tackled by similar thing. Whole problem was with netbeans deploying. They overwrite the settings in glassfish connection pool and when you set them proper at runtime, you got npe's or missing password silly stuff. The place to edit this is sun-resources.xml. XML element has attributes datasource-classname and rs-type. What needs to be done in case of Derby database is:

<jdbc-connection-pool ... 
        datasource-classname="org.apache.derby.jdbc.ClientXADataSource" 
        res-type="javax.sql.XADataSource">
   ...
</jdbc-connection-pool>

现在就像魅力一样。

这篇关于如何防止“本地交易已经有1个非XA资源”例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆