I'm trying to figure out how to get Glassfish to automatically re-connect
to a SQL Server database when the connection is lost. The connection could
be loss because the database when down or the network connection goes down,
among other things. When the connection is lost I get an exception that
tell me that, which is fine. However when the db comes back online I can't
get/create another connection from the connection pool. The code I'm using
to get a new connection after the db connection has gone down and come back
up is pretty straight forward, but I get an exception.
DataSource ds = (DataSource)this.initialContext.lookup("jdbc/SQLServer");
this.connection = ds.getConnection(); Exception:
java.sql.SQLException: Error in allocating a connection. Cause:
java.lang.IllegalStateException: Wrong XAState: 3 at
com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:120) at
com.foo.dao.PersistenceManager.initConnection(PersistenceManager.java:203) at
com.foo.dao.PersistenceManager.persist(PersistenceManager.java:376) at
com.foo.ejb.message.PersistListenerEJB.onMessage(PersistListenerEJB.java:42)
at sun.reflect.GeneratedMethodAccessor105.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at
org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at
com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4154)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5346)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326) at
com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1093)
at
com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:81)
at
com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:171)
at $Proxy383.onMessage(Unknown Source) at
com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:260) at
com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:114) at
com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at
com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: javax.resource.spi.ResourceAllocationException: Error in
allocating a connection. Cause: java.lang.IllegalStateException: Wrong
XAState: 3 at
com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:113) ... 19
more Caused by: com.sun.appserv.connectors.internal.api.PoolingException:
java.lang.IllegalStateException: Wrong XAState: 3 at
com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:218)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:338)
at
com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:301)
... 23 more Caused by:
com.sun.appserv.connectors.internal.api.PoolingException:
java.lang.IllegalStateException: Wrong XAState: 3 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:208)
... 25 more Caused by: java.lang.IllegalStateException: Wrong XAState: 3 at
com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:322)
at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:212)
at
com.sun.enterprise.transaction.JavaEETransactionImpl.enlistResource(JavaEETransactionImpl.java:639)
at
com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.enlistDistributedNonXAResource(JavaEETransactionManagerJTSDelegate.java:301)
at
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:384)
at
com.sun.enterprise.resource.rm.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:152)
... 27 more
--
[Message sent by forum member 'cain05']
View Post: http://forums.java.net/node/838249