I’ve read somewhere that when a session is flushed or a transaction is committed, the session itself is closed by Hibernate. So, how can i reuse an Hibernate Session, in the same thread, that has been previously closed?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
flushdoes not close the session. However, starting from Hibernate 3.1, acommitwill close the session if you configuredcurrent_session_context_classto “thread” or “jta“, or if you are using aTransactionManagerLookup(mandatory JTA) andgetCurrentSession().The following code illustrates this (with
current_session_context_classset totheadhere):See this thread and the section 2.5. Contextual sessions in the documentation for background on this.
Either use the built-in “
managed” strategy (set thecurrent_session_context_classproperty tomanaged) or use a customCurrentSessionContextderived fromThreadLocalSessionContextand overrideThreadLocalSessionContet.isAutoCloseEnabled().Again, see the above links and also What about the extended Session pattern for long Conversations?