2

I have written a code to connect to oracle database and retrieve some data. I opened session and close it properly but it is appearing that its not closing properly. I found it by query to get total in active sessions and its increasing which is very strange. My code to get data and to to query inactive sessions is as follows. Its appearing that session.close() function is not working but i don't know why? I am using Glassfish, JSF and 10g oracle database.

select count(s.status) INACTIVE_SESSIONS
from gv$session s, v$process p
where
p.addr=s.paddr and
s.status='INACTIVE';

public List<TrxTender> getFileDetails() {
        java.util.List l = null;
try {
            sess = sessFactory.openSession();
            Query q = sess.createQuery("from mytable");
            l = q.list();
            return l;
        } catch (HibernateException hbx) {
            hbx.printStackTrace();
        } finally {
            sess.flush();
            sess.close();
        }
        return l;
    }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sam
  • 39
  • 6
  • check http://stackoverflow.com/questions/20976322/close-sessionfactory-in-hibernate-4-3 and http://stackoverflow.com/questions/15298437/hibernate-closing-the-session-factory-does-not-close-the-c3p0-connection-pool – Sai Ye Yan Naing Aye Apr 28 '15 at 07:36
  • I have used jdbc connection pool in Glassfish but the problem remains same there is memory leaks i think again memory leaks are on sess.close()... beacuase i used hibernate so its error came that java.lang.OutOfMemoryError: Java heap space. how to close the connection/session please help. or how to get rid of it in hibernate – sam Apr 29 '15 at 03:30
  • check this sample usage http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial-firstapp-helpers – Sai Ye Yan Naing Aye Apr 29 '15 at 03:44
  • i am not talking about sessionsFactory but Session sess=SessionFactory.opensession();.... means ia mtalking about how to close session?? – sam Apr 29 '15 at 04:00

1 Answers1

0

Use below property in hibernate configuration file, so that you need not close the session explicitly.

&ltproperty name="current_session_context_class"&gtthread&lt/property&gt
శ్రీ
  • 143
  • 10