users@glassfish.java.net

Re: Error in allocating a connection

From: <glassfish_at_javadesktop.org>
Date: Thu, 02 Sep 2010 06:30:10 PDT

I see now in server.log
A potential connection leak detected for connection pool imaRMSProd. The stack trace of the thread is provided below : and it points to our ConnectionAdapter class.
I thought this class is implemented corrected as per the Glassfish developer guide

public class WSConnectionAdapter implements ConnectionAdapter {
   private static Logger logger = Logger.getLogger(WSConnectionAdapter.class);
   private DataSource dataSource;
   private Connection sunConn = null;
   
   public WSConnectionAdapter(DataSource dataSource) {
      this.dataSource = dataSource;
   }
   
   public Connection getConnection() {
           
           Connection con = null;
      try {

              sunConn = dataSource.getConnection();
              con = dataSource.getConnection(sunConn);
         
      } catch (SQLException ex) {
         logger.fatal("failed to get native connection to database", ex);
         throw new IMADataException("failed to get native connection to database", ex);
      }
      return con;
   }
   
   public void closeConnection() {
           try {
                   if( sunConn != null)
                           sunConn.close();
           }catch (SQLException ex) {
                 logger.fatal("failed to close connection to database", ex);
                 throw new IMADataException("failed to close connection to database", ex);
            }
   }
}

Guide states driver connection ( i.e con obj) should never be closed

Any suggestions on this class

Applicationcontext.xml has
<bean id="rmsDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
   <property name="jndiName" value="jdbc/test/rms12" />
   <property name="lookupOnStartup" value="false" />
   <property name="cache" value="true" />
   <property name="proxyInterface" value="com.sun.appserv.jdbc.DataSource" />
</bean>

<!-- Hibernate SessionFactory -->
<bean id="rmsSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <!--property name="dataSource" ref="dataSource" /-->
        <property name="dataSource" ref="rmsDataSource" />
        <property name="useTransactionAwareDataSource" value="true" />
        <property name="hibernateProperties" ref="hibernateProperties" />

..............

Any suggestions or is this incorrect...
[Message sent by forum member 'sapnasamdavid']

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