You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by anenvyguest2 <lo...@fastmail.fm> on 2011/03/23 12:25:31 UTC

IBM JDK + HSQLDB + OpenEJB - problems with entity manager: Connection does not have a registered XAResource

Hi, 
I'm using IBM JDK (1.6) and having troubles running OpenEJB "injection of
entity manager" example.
So, I have downloaded examples, changed to "injection-of-entitymanager"
directory and ran Maven.

Here is the exception I've got:


INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default
Stateful Container)
INFO - Deployed Application(path=classpath.ear)
WARN - Unexpected exception from beforeCompletion; transaction will roll
back
 org.apache.openjpa.persistence.PersistenceException: Connection does not
have a registered XAResource
 jdbc:hsqldb:mem:moviedb, UserName=SA, HSQL Database Engine Driver
        at
org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4232)
        at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4197)
        at
org.apache.openjpa.jdbc.sql.HSQLDictionary.newStoreException(HSQLDictionary.java:292)
        at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
        at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:88)
        at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:64)
        at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connect(JDBCStoreManager.java:930)
        at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.retainConnection(JDBCStoreManager.java:216)
        at
org.apache.openjpa.kernel.DelegatingStoreManager.retainConnection(DelegatingStoreManager.java:163)
        at
org.apache.openjpa.kernel.BrokerImpl.retainConnection(BrokerImpl.java:3710)
        at
org.apache.openjpa.kernel.BrokerImpl.beginStoreManagerTransaction(BrokerImpl.java:1283)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1968)
        at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
        at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1826)
        at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
        at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
        at
org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
        at
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
        at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:291)
        at
org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
        at
org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:74)
        at
org.apache.openejb.core.stateful.StatefulContainer.afterInvoke(StatefulContainer.java:799)
        at
org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:567)
        at
org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:325)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
        at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
        at $Proxy26.addMovie(Unknown Source)
        at org.superbiz.injection.jpa.MoviesTest.test(MoviesTest.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at junit.framework.TestCase.runTest(TestCase.java:164)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:228)
        at junit.framework.TestSuite.run(TestSuite.java:223)
        at
org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
        at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
        at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at
org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
        at $Proxy0.invoke(Unknown Source)
        at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
        at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
        at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by:
java.sql.SQLException: Connection does not have a registered XAResource
jdbc:hsqldb:mem:moviedb, UserName=SA, HSQL Database Engine Driver
        at
org.apache.commons.dbcp.managed.TransactionRegistry.getXAResource(TransactionRegistry.java:76)
        at
org.apache.commons.dbcp.managed.TransactionContext.setSharedConnection(TransactionContext.java:88)
        at
org.apache.commons.dbcp.managed.ManagedConnection.updateTransactionStatus(ManagedConnection.java:131)
        at
org.apache.commons.dbcp.managed.ManagedConnection.(ManagedConnection.java:55)
        at
org.apache.commons.dbcp.managed.ManagedDataSource.getConnection(ManagedDataSource.java:77)
        at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:884)
        at
org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:106)
        at
org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:87)
        at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connectInternal(JDBCStoreManager.java:941)
        at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connect(JDBCStoreManager.java:926)
        ... 48 more
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.708 sec
<<< FAILURE!



I don't have such troubles when using Oracle JDK (1.6.24)
Any idea how to fix this? Changing JDK is not an option in my case.
Thank you!

--
View this message in context: http://openejb.979440.n4.nabble.com/IBM-JDK-HSQLDB-OpenEJB-problems-with-entity-manager-Connection-does-not-have-a-registered-XAResource-tp3399239p3399239.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: IBM JDK + HSQLDB + OpenEJB - problems with entity manager: Connection does not have a registered XAResource

Posted by Kevan Miller <ke...@gmail.com>.
On Aug 1, 2011, at 8:54 AM, Shawn Jiang wrote:

> I met the same problem when running embeded ejb  with geronimo
> 3.0-snapshot.    After some debug,  I found that the exception was thrown
> from this class.
> 
> org.apache.commons.dbcp.managed.TransactionRegistry
> 
> {
> 
>    private final Map *xaResources *= new WeakHashMap();
> 
> ...
> public synchronized XAResource getXAResource(Connection connection) throws
> SQLException {
>        if (connection == null) throw new NullPointerException("connection
> is null");
>        XAResource xaResource = (XAResource) *xaResources*.get(connection);
>        if (xaResource == null) {
>            throw new SQLException("Connection does not have a registered
> XAResource " + connection);
>        }
>        return xaResource;
>    }
> 
> ...
> }
> 
> The XAResource was registered with connection as key.    the method
> getXAResource is used to fetch the corresponding XAResrouce later.   a
> wrappered connecion was passed and in Oracle JDK.  the
> xaResource.get(connection)  could get the xaResource out.
> 
> But for IBM JDK, the xaResources.get(connection) will return null.     And
> then result in the SQLException.     I believe it's caused by the
> WeakHashMap implementation difference between Oracle JDK and IBM JDK.
> 
> 
> I changed
> 
> private final Map *xaResources *= new WeakHashMap();
> 
> to
> 
> private final Map *xaResources *= new HashMap();
> 
> and it works for me.   I guess the HashMap.get()   behavior of both JDK are
> the same.     Hope it helps.

Although all the other WeakHashMaps used by commons-dbcp appear to be pretty useless (there will always be strong references to the keys), the xaResources WeakHashMap might actually server a purpose... Better, IMO to do this:

Index: src/java/org/apache/commons/dbcp/managed/TransactionRegistry.java
===================================================================
--- src/java/org/apache/commons/dbcp/managed/TransactionRegistry.java	(revision 699049)
+++ src/java/org/apache/commons/dbcp/managed/TransactionRegistry.java	(working copy)
@@ -27,6 +27,8 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
+import org.apache.commons.dbcp.DelegatingConnection;
+
 /**
  * TransactionRegistry tracks Connections and XAResources in a transacted environment for a single XAConnectionFactory.
  * </p>
@@ -71,6 +73,9 @@
      */
     public synchronized XAResource getXAResource(Connection connection) throws SQLException {
         if (connection == null) throw new NullPointerException("connection is null");
+        if (connection instanceof DelegatingConnection) {
+            connection = ((DelegatingConnection)connection).getInnermostDelegate();
+        }
         XAResource xaResource = (XAResource) xaResources.get(connection);
         if (xaResource == null) {
             throw new SQLException("Connection does not have a registered XAResource " + connection);

--kevan

Re: IBM JDK + HSQLDB + OpenEJB - problems with entity manager: Connection does not have a registered XAResource

Posted by Shawn Jiang <ge...@gmail.com>.
I met the same problem when running embeded ejb  with geronimo
3.0-snapshot.    After some debug,  I found that the exception was thrown
from this class.

org.apache.commons.dbcp.managed.TransactionRegistry

{

    private final Map *xaResources *= new WeakHashMap();

...
 public synchronized XAResource getXAResource(Connection connection) throws
SQLException {
        if (connection == null) throw new NullPointerException("connection
is null");
        XAResource xaResource = (XAResource) *xaResources*.get(connection);
        if (xaResource == null) {
            throw new SQLException("Connection does not have a registered
XAResource " + connection);
        }
        return xaResource;
    }

...
}

The XAResource was registered with connection as key.    the method
getXAResource is used to fetch the corresponding XAResrouce later.   a
wrappered connecion was passed and in Oracle JDK.  the
xaResource.get(connection)  could get the xaResource out.

But for IBM JDK, the xaResources.get(connection) will return null.     And
then result in the SQLException.     I believe it's caused by the
WeakHashMap implementation difference between Oracle JDK and IBM JDK.


I changed

private final Map *xaResources *= new WeakHashMap();

to

private final Map *xaResources *= new HashMap();

and it works for me.   I guess the HashMap.get()   behavior of both JDK are
the same.     Hope it helps.

On Wed, Mar 23, 2011 at 7:25 PM, anenvyguest2 <lo...@fastmail.fm> wrote:

> Hi,
> I'm using IBM JDK (1.6) and having troubles running OpenEJB "injection of
> entity manager" example.
> So, I have downloaded examples, changed to "injection-of-entitymanager"
> directory and ran Maven.
>
> Here is the exception I've got:
>
>
> INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default
> Stateful Container)
> INFO - Deployed Application(path=classpath.ear)
> WARN - Unexpected exception from beforeCompletion; transaction will roll
> back
>  org.apache.openjpa.persistence.PersistenceException: Connection does not
> have a registered XAResource
>  jdbc:hsqldb:mem:moviedb, UserName=SA, HSQL Database Engine Driver
>        at
> org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4232)
>        at
>
> org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4197)
>        at
>
> org.apache.openjpa.jdbc.sql.HSQLDictionary.newStoreException(HSQLDictionary.java:292)
>        at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
>        at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:88)
>        at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:64)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connect(JDBCStoreManager.java:930)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.retainConnection(JDBCStoreManager.java:216)
>        at
>
> org.apache.openjpa.kernel.DelegatingStoreManager.retainConnection(DelegatingStoreManager.java:163)
>        at
> org.apache.openjpa.kernel.BrokerImpl.retainConnection(BrokerImpl.java:3710)
>        at
>
> org.apache.openjpa.kernel.BrokerImpl.beginStoreManagerTransaction(BrokerImpl.java:1283)
>        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1968)
>        at
> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
>        at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1826)
>        at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
>        at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
>        at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
>        at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
>        at
>
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
>        at
>
> org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:291)
>        at
> org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
>        at
>
> org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:74)
>        at
>
> org.apache.openejb.core.stateful.StatefulContainer.afterInvoke(StatefulContainer.java:799)
>        at
>
> org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:567)
>        at
>
> org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:325)
>        at
>
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
>        at
>
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
>        at
>
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
>        at $Proxy26.addMovie(Unknown Source)
>        at org.superbiz.injection.jpa.MoviesTest.test(MoviesTest.java:45)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:611)
>        at junit.framework.TestCase.runTest(TestCase.java:164)
>        at junit.framework.TestCase.runBare(TestCase.java:130)
>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>        at junit.framework.TestResult.run(TestResult.java:113)
>        at junit.framework.TestCase.run(TestCase.java:120)
>        at junit.framework.TestSuite.runTest(TestSuite.java:228)
>        at junit.framework.TestSuite.run(TestSuite.java:223)
>        at
>
> org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
>        at
>
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
>        at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:611)
>        at
>
> org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
>        at $Proxy0.invoke(Unknown Source)
>        at
>
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
>        at
>
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
>        at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
> Caused by:
> java.sql.SQLException: Connection does not have a registered XAResource
> jdbc:hsqldb:mem:moviedb, UserName=SA, HSQL Database Engine Driver
>        at
>
> org.apache.commons.dbcp.managed.TransactionRegistry.getXAResource(TransactionRegistry.java:76)
>        at
>
> org.apache.commons.dbcp.managed.TransactionContext.setSharedConnection(TransactionContext.java:88)
>        at
>
> org.apache.commons.dbcp.managed.ManagedConnection.updateTransactionStatus(ManagedConnection.java:131)
>        at
>
> org.apache.commons.dbcp.managed.ManagedConnection.(ManagedConnection.java:55)
>        at
>
> org.apache.commons.dbcp.managed.ManagedDataSource.getConnection(ManagedDataSource.java:77)
>        at
>
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:884)
>        at
>
> org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:106)
>        at
>
> org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:87)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connectInternal(JDBCStoreManager.java:941)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.connect(JDBCStoreManager.java:926)
>        ... 48 more
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.708 sec
> <<< FAILURE!
>
>
>
> I don't have such troubles when using Oracle JDK (1.6.24)
> Any idea how to fix this? Changing JDK is not an option in my case.
> Thank you!
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/IBM-JDK-HSQLDB-OpenEJB-problems-with-entity-manager-Connection-does-not-have-a-registered-XAResource-tp3399239p3399239.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>



-- 
Shawn