title: Cannot set custom CurrentSessionContext class in Spring Session Factory
body: <p>I am trying to implement a Session-Per-Conversation pattern in a JSF2-Spring-Hibernate Web App so I need my AnnotationSessionFactoryBean to build a Hibernate SessionFactory with a custom CurrentSessionContext class.</p>
  
  <p>I have been receiving this error log:</p>
  
  <pre><code>org.springframework.dao.DataAccessResourceFailureException: Could not obtain Hibernate-managed Session for Spring-managed transaction; nested exception is org.hibernate.HibernateException: No CurrentSessionContext configured!
  </code></pre>
  
  <p>Here is my xml config for the whole data context used.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="${datasource.driverClassName}" /&gt;
          &lt;property name="url" value="${datasource.url}" /&gt;
          &lt;property name="username" value="${datasource.username}" /&gt;
          &lt;property name="password" value="${datasource.password}" /&gt;
          &lt;property name="initialSize" value="${datasource.poolInitialSize}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${org.hibernate.dialect.dialectmysqlInno}&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;${org.hibernate.ddl.mode}&lt;/prop&gt;
                  &lt;prop key="hibernate.search.default.directory_provider"&gt;${org.hibernate.search.directoryprovidr}&lt;/prop&gt;
                  &lt;prop key="hibernate.current_session_context_class"&gt;
                      mx.gob.jgtjo.apps.schedule.web.conversation.ConversationalCurrentSessionContext
                  &lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="hibernateManagedSession" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven order="0" transaction-manager="transactionManager" /&gt;
  
      &lt;context:component-scan base-package="mx.gob.jgtjo.apps.schedule.dao.hibernate" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Also, here is my hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory name="jgtjoSessionFactory"&gt;
          &lt;!--Entity --&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.AudienciaOral" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.CausaPenal" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.DefensorPenal" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.Delito" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.EventoAudiencia" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.Juez" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.MinisterioPublico" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.ParteMaterial" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.Sala" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.TipoAudiencia" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.User" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.Rol" /&gt;
          &lt;mapping class="mx.gob.jgtjo.apps.schedule.model.DelitoConfigurado" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>As you can see, nothing tricky with hibernate xml.</p>
  
  <p>Why I keep getting this exception?</p>
  
  <pre><code>java.lang.NoSuchMethodException: mx.gob.jgtjo.apps.schedule.web.conversation.ConversationalCurrentSessionContext.&lt;init&gt;(org.hibernate.engine.SessionFactoryImplementor)
  </code></pre>
  
  <p>It seems that hibernate looks for a constructor in my class that has a SessionFactory as argument.</p>