I have applied the setting suggest in the forum faq :
Websphere 5 produces a com.ibm.websphere.ce.cm.StaleConnectionException: Connection is closed
Unfortunately on WebSphere 5.0 I get the following error message when closing a Hibernate Session:
net.sf.hibernate.util.JDBCExceptionReporter TRAS0014I: The following exception was logged com.ibm.websphere.ce.cm.StaleConnectionException: Connection is closed
We had this same problem with data source connections in Websphere. We "fixed" it by configuring the data source to "Disable auto connection cleanup". It's a checkbox in the data source setup in Websphere.
This is how i am getting the connection : (We have various databases on different machines) :
Code:
public static Connection getConnection (String dataSourceName)
throws ServletException
{
String dataSourceNameToUse = dataSourceName;
if ((dataSourceName.equals (DATA_SOURCE_RENEWALS)) &&
(!getDatabaseMode ().equals (CPAConstants.DATABASE_MODE_REMOTE_LINK_TO_RENEWALS_DATABASE)))
{
dataSourceNameToUse = DATA_SOURCE_RENEWALS_BACKUP;
}
if ((dataSourceName.equals (DATA_SOURCE_GLOBE_DIRECT)) &&
(getDatabaseMode ().equals (CPAConstants.DATABASE_MODE_NO_INSTRUCTIONS)))
{
throw new ServletException ("Globe Direct library is not accessible in current Database Mode");
}
String dataSourceURL = DatabaseUtilities.getDatabaseProperties (DATABASE_PROPERTIES_FILE).getProperty (dataSourceNameToUse);
if (dataSourceURL == null) {
log.fatal("Could not obtain JNDI name of data source " + dataSourceNameToUse + " from properties file");
throw new ServletException ("Could not obtain JNDI name of data source " + dataSourceNameToUse + " from properties file");
}
Connection conn;
try
{
conn = DatabaseUtilities.getConnection (dataSourceURL);
}
catch (SQLException e)
{
log.fatal("SQL exception obtaining connection to " + dataSourceNameToUse + " URL:" + dataSourceURL + ": ", e);
throw new ServletException ("SQL exception obtaining connection to " + dataSourceNameToUse + ": " + e);
}
catch (NamingException e)
{
log.fatal("Naming exception obtaining connection to " + dataSourceNameToUse + " URL:" + dataSourceURL + ": ", e);
throw new ServletException ("Naming exception obtaining connection to " + dataSourceNameToUse + ": " + e);
}
return conn;
}
And after running the server for a while i am getting staleconnection exception !!
Code:
[18/11/03 10:48:49:274 UTC] 15caa8f1 ConnectionPoo X CONM6009E: Failed to get connection to the database from datasource (Globe Direct Database).
[18/11/03 10:48:49:376 UTC] 15caa8f1 StaleConnecti A CONM7007I: Mapping the following SQLException, with ErrorCode -30,080 and SQLState 08001, to a StaleConnectionException: com.ibm.db2.jdbc.app.DB2DBException: Communication error occurred during distributed database processing.
java/lang/Throwable.<init>(Ljava/lang/String;)V+4 (Throwable.java:90)
java/lang/Exception.<init>(Ljava/lang/String;)V+1 (Exception.java:38)
java/sql/SQLException.<init>(Ljava/lang/String;Ljava/lang/String;I)V+1 (SQLException.java:39)
com/ibm/db2/jdbc/app/DB2SQLException2.<init>(Ljava/lang/String;Ljava/lang/String;I[B)V+1 (DB2SQLException2.java:40)
com/ibm/db2/jdbc/app/DB2DBException.<init>(Ljava/lang/String;Ljava/lang/String;I[B)V+1 (DB2DBException.java:47)
com/ibm/db2/jdbc/app/DB2ConnectionRuntimeImpl.connect(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)I+70 (DB2ConnectionRuntimeImpl.java:98)
com/ibm/db2/jdbc/app/DB2Connection.<init>(Ljava/lang/String;Ljava/util/Properties;Z)V+206 (DB2Connection.java:320)
com/ibm/db2/jdbc/app/DB2StdPooledConnection.initPhysicalConnection(Z)V+51 (DB2StdPooledConnection.java:111)
com/ibm/db2/jdbc/app/DB2StdConnectionPoolDataSource.getPooledConnection()Ljavax/sql/PooledConnection;+24 (DB2StdConnectionPoolDataSource.java:71)
com/ibm/ejs/cm/pool/JDBC1xConnectionFactory.createConnection(Lcom/ibm/ejs/cm/pool/ConnectionPool;)Lcom/ibm/ejs/cm/pool/ConnectO;+8 (JDBC1xConnectionFactory.java:32)
com/ibm/ejs/cm/pool/ConnectionPool.createConnection(Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/ejs/cm/pool/ConnectO;+42 (ConnectionPool.java:1073)
com/ibm/ejs/cm/pool/ConnectionPool.createOrWaitForConnection(Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/ejs/cm/pool/ConnectO;+186 (ConnectionPool.java:983)
com/ibm/ejs/cm/pool/ConnectionPool.findFreeConnection(Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/ejs/cm/pool/ConnectO;+126 (ConnectionPool.java:921)
com/ibm/ejs/cm/pool/ConnectionPool.findConnectionForTx(Lorg/omg/CosTransactions/Coordinator;Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/ejs/cm/pool/ConnectO;+192 (ConnectionPool.java:789)
com/ibm/ejs/cm/pool/ConnectionPool.getConnection(Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;+1 (ConnectionPool.java:322)
com/ibm/ejs/cm/DataSourceImpl$1.run()Ljava/lang/Object;+15 (DataSourceImpl.java:135)
com/ibm/ejs/cm/DataSourceImpl.getConnection(Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;+77 (DataSourceImpl.java:133)
com/ibm/ejs/cm/DataSourceImpl.getConnection()Ljava/sql/Connection;+19 (DataSourceImpl.java:102)
com/cpaglobal/servletutilities/DatabaseUtilities.getConnection(Ljava/lang/String;)Ljava/sql/Connection;+0 (DatabaseUtilities.java:73)
com/cpaglobal/servletutilities/CPAJdbcServletBase.getConnection(Ljava/lang/String;)Ljava/sql/Connection;+0 (CPAJdbcServletBase.java:181)
com/cpaglobal/cpadirect/servlet/ShowReminderServlet.handleRequest(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+0 (ShowReminderServlet.java:53)
com/cpaglobal/servletutilities/CPAServletBase.handleGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+0 (CPAServletBase.java:217)
com/cpaglobal/servletutilities/CPAServletBase.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+0 (CPAServletBase.java:57)
javax/servlet/http/HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+32 (HttpServlet.java:740)
javax/servlet/http/HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+26 (HttpServlet.java:853)
com/ibm/servlet/engine/webapp/StrictServletInstance.doService(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+21 (ServletManager.java:827)
com/ibm/servlet/engine/webapp/StrictLifecycleServlet._service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+69 (StrictLifecycleServlet.java:167)
com/ibm/servlet/engine/webapp/ServletInstance.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Lcom/ibm/servlet/engine/webapp/WebAppServletInvocationEvent;)V+186 (ServletManager.java:472)
com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.handleWebAppDispatch(Lcom/ibm/servlet/engine/webapp/WebAppRequest;Ljavax/servlet/http/HttpServletResponse;)V+817 (WebAppRequestDispatcher.java:721)
com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.dispatch(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Z)V+1080 (WebAppRequestDispatcher.java:374)
com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.forward(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+85 (WebAppRequestDispatcher.java:118)
com/ibm/servlet/engine/srt/WebAppInvoker.doForward(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+234 (WebAppInvoker.java:134)
com/ibm/servlet/engine/srt/WebAppInvoker.handleInvocationHook(Ljava/lang/Object;)V+175 (WebAppInvoker.java:239)
com/ibm/servlet/engine/invocation/CachedInvocation.handleInvocation(Ljava/lang/Object;)V+25 (CachedInvocation.java:67)
com/ibm/servlet/engine/srp/ServletRequestProcessor.dispatchByURI(Ljava/lang/String;Lcom/ibm/servlet/engine/srp/ISRPConnection;)V+709 (ServletRequestProcessor.java:151)
com/ibm/servlet/engine/oselistener/OSEListenerDispatcher.service(Lcom/ibm/servlet/engine/oselistener/api/IOSEConnection;)V+104 (OSEListener.java:315)
com/ibm/servlet/engine/http11/HttpConnection.handleRequest()V+4 (HttpConnection.java:60)
com/ibm/ws/http/HttpConnection.readAndHandleRequest()V+50 (HttpConnection.java:323)
com/ibm/ws/http/HttpConnection.run()V+195 (HttpConnection.java:252)
com/ibm/ws/util/CachedThread.run()V+18 (ThreadPool.java:138)
[18/11/03 10:48:49:410 UTC] 15caa8f1 WebGroup I SRVE0091I: [Servlet LOG]: ShowReminderServlet (19): Message 'doGet: Class com.cpaglobal.cpadirect.servlet.ShowReminderServlet@77461f3f exception javax.servlet.ServletException: SQL exception obtaining connection to connection.globecpadirect.datasource: com.ibm.websphere.ce.cm.StaleConnectionException: Communication error occurred during distributed database processing.' at Tue Nov 18 10:48:49 UTC 2003 from class [com.cpaglobal.cpadirect.servlet.ShowReminderServlet]
I know this is not Hibernate related, but we are planning to replace this legacy code, and this kind of issue will still be around. Could anyone help pleace :(
MIke