java 获取 JDBC 连接时出错:无法在输入元感知对象时登记事务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3826974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error getting JDBC Connection: Could not enlist in transaction on entering meta-aware object
提问by rfders
I am having a problem getting a JDBC connection in an EJB SessionBean
. The error is:
我在EJB SessionBean
. 错误是:
org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings.
org.jboss.util.NestedSQLException:无法在进入元感知对象的事务中登记!;- 嵌套 throwable: (javax.transaction.SystemException: java.lang.Throwable: 无法征用资源,请参阅前面的警告。
I thought this happens, because I already have an open connection from a different datasource, so I configured an XA datasourceto avoid transaction problems, but it doesn't work at all, so I don't know if I am doing something wrong in my code. Here it is:
我以为会发生这种情况,因为我已经有一个来自不同数据源的开放连接,所以我配置了一个XA 数据源以避免事务问题,但它根本不起作用,所以我不知道我是否做错了什么我的代码。这里是:
try
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL,"jnp://localhost:11099");
p.put("java.naming.factory.url.pkgs", "org.jboss.naming");
InitialContext ic = new InitialContext(p);
DataSource dataSource = (DataSource)ic.lookup("java:/jdbc/etlreportservices");
return dataSource.getConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
The exception is thrown while calling dataSource.getConnection()
.
调用时抛出异常dataSource.getConnection()
。
采纳答案by rfders
I changed my transaction manager to be bean-managed and it works perfectly.
我将我的事务管理器更改为 bean 管理,它运行良好。
回答by Yaro
Can try, for old Jboss-es: /server/all/conf/jbossjta-properties.xml
可以尝试,对于旧的 Jboss-es:/server/all/conf/jbossjta-properties.xml
<properties depends="arjuna" name="jta">
<property name="com.arjuna.ats.jta.allowMultipleLastResources" value="true"/>
</properties>
for new: standalone\configuration\standalone.xml (or other what you use)
对于新的:standalone\configuration\standalone.xml(或其他你使用的)
<system-properties>
<property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
</system-properties>
回答by Alexx
I have noticed this in cases where the tx times out. FWIW.
在 tx 超时的情况下,我注意到了这一点。FWIW。
回答by Beryllium
Using JBoss 6.0.0, the error message is slightly different:
使用 JBoss 6.0.0,错误信息略有不同:
Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!
引起:org.jboss.resource.JBossResourceException:无法在进入元感知对象时登记事务!
As for the reason: A quote from here
至于原因:引自这里
Within the same process, two calls were being made to different non-XA data sources. This is not supported by default on JBoss.
在同一个过程中,对不同的非 XA 数据源进行了两次调用。JBoss 默认不支持此功能。
The same site shows a solution which was not applicable for JBoss 6.0.0.
同一个站点显示了一个不适用于 JBoss 6.0.0 的解决方案。
The general solution is to change alldata sources involved in the same transaction into XA data sources. Then it works both with bean managedand container managed transactions. For example, this solution is proposed in a CodeRanchand in a JBoss forumas well.
一般的解决方案是将同一事务中涉及的所有数据源都更改为XA 数据源。然后,它与工作两者Bean管理和容器管理的事务。例如,在CodeRanch和JBoss 论坛中也提出了此解决方案。