Exception:org.hibernate.HibernateException: No CurrentSessionContext configured!


If you get an exception while using Hibernate;
org.hibernate.HibernateException: No CurrentSessionContext configured! org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542) com.tunatore.hibernateexample.HibernateExample.getCustomersInState(HibernateExample.java:22) org.apache.jsp.index_jsp._jspService(index_jsp.java:73) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

Add the following line inside hibernate.cfg.xml file

<property name=”current_session_context_class”>thread</property>

like the following;

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 3.0//EN”
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”&gt;

<hibernate-configuration>
  <session-factory>
    <property name=”hibernate.dialect”>org.hibernate.dialect.DerbyDialect</property>
    <property name=”hibernate.connection.driver_class”>org.apache.derby.jdbc.ClientDriver</property>
    <property name=”hibernate.connection.url”>jdbc:derby://localhost:1527/sample</property>
    <property name=”hibernate.connection.username”>app</property>
    <property name=”hibernate.connection.password”>app</property>
<property name=”current_session_context_class”>thread</property>
  </session-factory>
</hibernate-configuration>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s