0

The point of my question is to find the way to determine whether session openned or uses current context. Is there a way to find if I used sessionFactory.getCurrentSession() or sessionFactory.openSession() to get my Hibernate Session object? something like: if used current session do nothing else close session manually.

Andronicus
  • 25,419
  • 17
  • 47
  • 88
janlan
  • 477
  • 1
  • 5
  • 19
  • Possible duplicate of [Control the hibernate session(when to close it manually)](https://stackoverflow.com/questions/4040761/control-the-hibernate-sessionwhen-to-close-it-manually) – LppEdd Apr 01 '19 at 19:26

1 Answers1

0

Not closing the session can cause memory leaks and that's independent from usage. That's why it's a good habit to use try-with-resource or put something like:

if(session != null) session.close();

in finally clause.

Andronicus
  • 25,419
  • 17
  • 47
  • 88