Hi,
I am using glassfish 4.1 with eclipselink 2.5.2 and JTA.
I get a NullPointerException when using different DB connections in
nested transactions (e.g. by using eclipselinks @Partitioning feature).
It looks to me that the wrong transaction gets picked when it comes to
processing the transaction in ResourceManagerImpl from the
connectors-runtime module. The situation is reproducible with following
code:
In an EJB with container managed transactions we have
// entry point is here
public void complexQuery(Long _id) {
TestTable table =
context.getBusinessObject(PersistenceTestBean.class).find(_id);
context.getBusinessObject(PersistenceTestBean.class).remove(table);
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public TestTable find(Long _id) {
// uses connection 1
TestTable t = em.find(TestTable.class, _id);
return t;
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void remove(TestTable _table) {
// uses connection 2
em.remove(em.merge(_table));
}
When it comes to execute the remove operation the
ResourceManagerImpl.registerResource(..) method is retrieving the
current transaction from the InvocationManager which happens to be NOT
the nested one but the one started when executing complexQuery.
This leads to following stack trace:
Query: DeleteObjectQuery(xyz.TestTable[ id=1 ])
at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:316)
at
org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:135)
at
org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
...
... 75 more
Caused by: java.sql.SQLException: Error in allocating a connection.
Cause: java.lang.RuntimeException: Got exception during XAResource.start:
at
com.sun.gjc.spi.base.AbstractDataSource.getConnection(AbstractDataSource.java:121)
at
org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:123)
... 106 more
Caused by: javax.resource.spi.ResourceAllocationException: Error in
allocating a connection. Cause: java.lang.RuntimeException: Got
exception during XAResource.start:
at
com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:319)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:196)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:171)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:166)
at
com.sun.gjc.spi.base.AbstractDataSource.getConnection(AbstractDataSource.java:114)
... 107 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException:
java.lang.RuntimeException: Got exception during XAResource.start:
at
com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:221)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:360)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307)
... 111 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException:
java.lang.RuntimeException: Got exception during XAResource.start:
at
com.sun.enterprise.resource.rm.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:173)
at
com.sun.enterprise.resource.rm.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:112)
at
com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:211)
... 113 more
Caused by: java.lang.RuntimeException: Got exception during
XAResource.start:
at
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:388)
at
com.sun.enterprise.resource.rm.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:152)
... 115 more
Caused by: javax.transaction.xa.XAException:
com.sun.appserv.connectors.internal.api.PoolingException:
java.lang.NullPointerException
at
com.sun.enterprise.resource.ConnectorXAResource.handleResourceException(ConnectorXAResource.java:115)
at
com.sun.enterprise.resource.ConnectorXAResource.start(ConnectorXAResource.java:150)
at
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:386)
... 116 more
Any help is appreciated.