title: Why this No Session found for current thread exceptions in spring 3.1 and hibernate 4
body: <p>I was trying to configure spring 3.1 and hibernate. I have written a simple test project. where I have user domain and userDao and its implementation </p>
  
  <p>let me show you may appliationContext      </p>
  
  <pre class="lang-xml prettyprint-override"><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:tx="http://www.springframework.org/schema/tx"
  xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;context:component-scan base-package="com.rokonoid.apps.user.dao"&gt;&lt;/context:component-scan&gt;
  
  &lt;!-- Data Source --&gt;
  
  &lt;context:property-placeholder location="classpath:/jdbc.properties" /&gt;
  &lt;bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="${database.driver}" /&gt;
      &lt;property name="url" value="${database.url}" /&gt;
      &lt;property name="username" value="${database.user}" /&gt;
      &lt;property name="password" value="${database.password}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
      &lt;property name="packagesToScan" value="com.rokonoid.apps.user.domain"&gt;&lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;prop key="hibernate.connection.pool_size"&gt;${hibernate.connection.pool_size}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;${hibernate.hbm2ddl.auto}&lt;/prop&gt;
              &lt;prop key="hibernate.query.substitutions"&gt;true=1 false=0&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>and part of UserDaoImpl </p>
  
  <pre><code> @Repository 
  public class UserDaoImpl implements UserDao {
  
  @Autowired
  private SessionFactory sessionFactory;
  
  @Override
  public User getUser(Long userId) {
      if (userId != null &amp;&amp; userId &gt; 0) {
          return (User) sessionFactory.getCurrentSession().get(User.class,
                  userId);
      }
      return null;
  }
  
  @Override
  public void updateUser(User user) {
      if (user != null) {
          sessionFactory.getCurrentSession().update(user);
      }
  }
  </code></pre>
  
  <p>it seems alright. But when I was trying to run my test cases I'm this exceptions. </p>
  
  <pre class="lang-none prettyprint-override"><code>org.hibernate.HibernateException: No Session found for current thread
  at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
  at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
  at com.rokonoid.apps.user.dao.UserDaoImpl.saveUser(UserDaoImpl.java:197)
  at com.rokonoid.apps.test.UserDaoTest.setUserTest(UserDaoTest.java:26)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
  at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
  at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>
  
  <p>Any kind of help is appreciated.</p>
  
  <p>Thanks </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Previous problem is solved, I have got another problem : 
  now I'm getting </p>
  
  <pre class="lang-none prettyprint-override"><code>java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
  at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:328)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  </code></pre>