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

4

9

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 
    {
        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().

Squiggle answered 30/9, 2010 at 0:54 Comment(3)
Is your EJB anotated with any transaction Anotation?Arne
The transaction is container-managedSquiggle
Thanks tomás you gave me an idea, i changed my transaction manager to be bean-managed and it works perfectlySquiggle
S
0

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

Squiggle answered 30/9, 2010 at 13:28 Comment(3)
Yeah, but how? This didn't help me very much. Probably the right answer but not thorough enough.Ingeminate
It would've been helpful if you added some code or description on how to change your transaction manager to be bean managed.Dumuzi
Had the same issue and it was because the bean was missing the @TransactionManagement(TransactionManagementType.BEAN) annotation.Dukey
H
7

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>  
Humbert answered 27/3, 2015 at 13:59 Comment(0)
A
1

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

Argyrol answered 21/4, 2011 at 5:8 Comment(0)
S
0

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

Squiggle answered 30/9, 2010 at 13:28 Comment(3)
Yeah, but how? This didn't help me very much. Probably the right answer but not thorough enough.Ingeminate
It would've been helpful if you added some code or description on how to change your transaction manager to be bean managed.Dumuzi
Had the same issue and it was because the bean was missing the @TransactionManagement(TransactionManagementType.BEAN) annotation.Dukey
P
0

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.

Peal answered 22/7, 2013 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.