After session.close() connection is still active with Database

Navnath picture Navnath · Apr 23, 2013 · Viewed 13.3k times · Source

I am working with swing and hibernate. Now for retrive connection, I am using sessionFactory.openSession(). Once I done with DB activity, I am closing same session by session.close(). Now the problem is, when I go on use my application, after some calls, appliation throws exception

40503 [AWT-EventQueue-0] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=12519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
    at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:418)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:521)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:325)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)

While using applicatin, I monitor active DB connections using following query

select count(*) from v$session

I come to know that connection count is go on increase, and after some connections DB stop giving new ones.

I don't know how to close connections with DB using hibernate as session.close() not useful to do so.

Answer