6

I am new to hibernate.

Does session.getTransaction().commit(), close the session? Because in the api documentation it is not mentioned that it closes the session.

In my code I have

session.getTransaction().commit();
session.close();

But I get following exception

org.hibernate.SessionException: Session was already closed

If I remove session.close(), then I do not get this exception.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Sagar Vaghela
  • 1,165
  • 5
  • 20
  • 38

1 Answers1

3

You can find more info about it here. Basically, this depends on how you obtained the session and what is performed in session.getTransaction().commit(); (transaction lifecycle listeners may close session here if some framework you use registered them, for example).

To check when it is really closed, you can try to set a breakpoint in AbstractSessionImpl.setClosed method.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110