开发者

Error getting JDBC Connection: Could not enlist in transaction on entering meta-aware object

I am having a problem getting a JDBC connection in an EJB SessionBean. The error is:

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.

I thought this happens, because I already have an open connection from a different datasource, so I configured an XA datasource to 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:

  try 
    {
        Prop开发者_运维知识库erties 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().


Can try, for old 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)

<system-properties>
    <property name="com.arjuna.ats.arjuna.allowMultipleLastResources"   value="true"/>
</system-properties>  


I have noticed this in cases where the tx times out. FWIW.


Using JBoss 6.0.0, the error message is slightly different:

Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!


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.

The same site shows a solution which was not applicable for JBoss 6.0.0.


The general solution is to change all data sources involved in the same transaction into XA data sources. Then it works both with bean managed and container managed transactions. For example, this solution is proposed in a CodeRanch and in a JBoss forum as well.


I changed my transaction manager to be bean-managed and it works perfectly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜