Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving an issue with org.hibernate.SessionException: Session is closed! in Hibernate
    text
    copied!<p>I've done quite a bit a research on this with no luck, but all the answers have a tendency to point toward the session context settings in the config file. What is odd is that I get a session connection the very first time I hit the page (and therefore, a successful result set), but then when I reload I get the following exception: org.hibernate.SessionException: Session is closed!</p> <p>Here are my config settings that are not DB connection string related:</p> <pre><code>&lt;property name="hibernate.show_sql"&gt;false&lt;/property&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt; &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt; &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt; &lt;property name="hibernate.cache.use_query_cache"&gt;false&lt;/property&gt; &lt;property name="hibernate.cache.use_minimal_puts"&gt;false&lt;/property&gt; </code></pre> <p>Here is an example of a call I make that produces the situation I described above.</p> <pre><code>public T get(int id) { session.beginTransaction(); T type; try { type = getTypeClass().cast(session.get(getTypeClass(), id)); } catch (ClassCastException classCastException) { throw new ClassCastException(classCastException.getMessage()); } session.getTransaction().commit(); return type; } </code></pre> <p>The session variable reference is to a static field that contains the current session. All of the session connection details are textbook reference manual. For example, here is my Hibernate session utility:</p> <pre><code>import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateSessionFactoryUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { return new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload