Reputation: 1547
Is there is any session/hibernate function to reconnect/reopen
LOG: SEVERE: No operations allowed after connection closed.
Upvotes: 1
Views: 7863
Reputation: 12058
Here is code example how to ensure the session is always valid. Line 2 must reassign back the session as openSession
returns a new session. Just session.getSessionFactory().openSession()
is not enough.
if (!session.isOpen()) {
session = session.getSessionFactory().openSession();
session.beginTransaction();
}
// operate your session
Criteria criteria = session.createCriteria(clazz);
Upvotes: 1
Reputation: 121998
Hibernate Docs about Seesion says
The lifecycle
of a Session
is bounded by the beginning and end of a logical transaction
. (Long transactions might span several database transactions.)
Once your transaction committed
,Session
wont available. You have to create a new one.
Upvotes: 0