users@glassfish.java.net

OracleXE, XADataSource, cannot get a Connection

From: <glassfish_at_javadesktop.org>
Date: Wed, 31 Dec 2008 06:33:10 PST

Hi. I am using OracleXE 10.2.0.1.0 and Glassfish v2. I added the necessary driver jar file to <Glassfish_dir>lib directory (ojdbc14.jar), and created a datasource like this:
1. Resources -> JDBC -> Connection Pools, clicked New
2. chose a name, chose the Resource Type to be javax.sql.XADataSource, clicked Next
3. in step 2, the class used was already set to oracle.jdbc.xa.client.OracleXADataSource (nice), so the only things I changed were the properties: DriverType(thin), ServerName(localhost), PortNumber(1521), DatabaseName(XE), User(test), Password(test). Clicked Finish
4. went to see the created pool details and clicked the Ping button, and it was successful

Then, I have a servlet with a button that calls a EJB that sends a JMS TextMessage to a Topic, and I also created a MDB listening for messages for that Topic. It has the default transaction attribute value, so that it is invoked in a transaction. The MDB has the DataSource injected. When I send the message via my simple servlet, the MDB is invoked, and I want to save the text of the message to my db, using plain JDBC. However, when I try to get a connection, there is an exception:
[code]
[#|2008-12-31T15:18:44.564+0100|WARNING|sun-appserver9.1|javax.enterprise.system.core.transaction|_ThreadID=22;_ThreadNa
me=p: thread-pool-1; w: 4;_RequestID=8280ec24-b98e-4c18-9a6f-2464600b27d1;|JTS5041: The resource manager is doing work o
utside a global transaction
oracle.jdbc.xa.OracleXAException
        at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:938)
        at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:244)
        at com.sun.gjc.spi.XAResourceImpl.start(XAResourceImpl.java:222)
        at com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:305)
        at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:205)
        at com.sun.enterprise.distributedtx.J2EETransaction.enlistResource(J2EETransaction.java:562)
        at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.enlistResource(J2EETransactionManagerImpl.java:37
2)
        at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:144)
        at com.sun.enterprise.resource.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:144)
        at com.sun.enterprise.resource.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:102)
        at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:216)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:337)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:235)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:158)
        at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:108)
        at impl.MessageListener.onMessage(MessageListener.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler
.java:179)
        at $Proxy54.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
[#|2008-12-31T15:18:44.574+0100|SEVERE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=22;_ThreadName=p: thread-pool-1; w: 4;_RequestID=8280ec24-b98e-4c18-9a6f-2464600b27d1;|RAR5029:Unexpected exception while registering component.
javax.transaction.SystemException
        at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:217)
        at com.sun.enterprise.distributedtx.J2EETransaction.enlistResource(J2EETransaction.java:562)
        at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.enlistResource(J2EETransactionManagerImpl.java:372)
        at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:144)
        at com.sun.enterprise.resource.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:144)
        at com.sun.enterprise.resource.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:102)
        at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:216)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:337)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:235)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
        at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:158)
        at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:108)
        at impl.MessageListener.onMessage(MessageListener.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
        at $Proxy54.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
[#|2008-12-31T15:18:44.584+0100|WARNING|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=22;_ThreadN
ame=p: thread-pool-1; w: 4;_RequestID=8280ec24-b98e-4c18-9a6f-2464600b27d1;|poolmgr.err_enlisting_res_in_getconn|#]

[#|2008-12-31T15:18:44.585+0100|WARNING|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=22;_ThreadN
ame=p: thread-pool-1; w: 4;jdbc/OracleXEPool;javax.transaction.SystemException;_RequestID=8280ec24-b98e-4c18-9a6f-246460
0b27d1;|RAR5117 : Failed to obtain/create connection from connection pool [ jdbc/OracleXEPool ]. Reason : javax.transact
ion.SystemException|#]

[#|2008-12-31T15:18:44.588+0100|WARNING|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=22;_ThreadN
ame=p: thread-pool-1; w: 4;Error in allocating a connection. Cause: javax.transaction.SystemException;_RequestID=8280ec2
4-b98e-4c18-9a6f-2464600b27d1;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: javax.t
ransaction.SystemException]|#]

[#|2008-12-31T15:18:45.585+0100|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=22;_ThreadName=p: thread-pool-1; w: 4;_RequestID=8280ec24-b98e-4c18-9a6f-2464600b27d1;|java.sql.SQLException: Error in allocating a connection. Cause: javax.transaction.SystemException
        at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:115)
        at impl.MessageListener.onMessage(MessageListener.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler
.java:179)
        at $Proxy54.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
[/code]
Then it tries to call prepare(), rollback() and so on and fails with further exceptions.

When I set the @TransactionAttribute to NOT_SUPPORTED, it works fine - that is, no exception is thrown, but this is not exactly what I want, I would like it transacted.

I searched for some information on this error, and found something putting the blame on the driver I have (this is the one that comes with the OracleXE installation). But, I can invoke this code from a standalone JSE client (with all needed jars like appserv-rt.jar i classpath, so that JNDi works):
[code]
        InitialContext ictx = new InitialContext();
        TransactionManager utm = (TransactionManager) ictx.lookup("java:appserver/TransactionManager");
        OracleXADataSource xds = new OracleXADataSource();
        xds.setDriverType("thin");
        xds.setNetworkProtocol("tcp");
        xds.setServerName("localhost");
        xds.setPortNumber(1521);
        xds.setDatabaseName("XE");
        xds.setUser("test");
        xds.setPassword("test");
        XAConnection xc = xds.getXAConnection();
        XAResource xar = xc.getXAResource();
        utm.begin();
        Transaction tx = utm.getTransaction();
        tx.enlistResource(xar);
        Connection c = xc.getConnection();
        c.createStatement().executeUpdate("INSERT INTO MESSAGES(TEXT) VALUES('test')");
        c.close();
        tx.rollback();
[/code]
and this works fine. It would mean it is an XA compliant resource?

Has anybody had similar problems with OracleXE and distributed transactions? I must be doing something wrong, but what?

Thank you.
[Message sent by forum member 'szczyp' (szczyp)]

http://forums.java.net/jive/thread.jspa?messageID=323708