title: Spring 4 Hibernate 4 No Session found for current thread
body: <p>I am getting the following exception in my web application. If you look closely, it appears to be going through the transactions managers, which means my point cuts are correct.</p>
  
  <pre><code>org.hibernate.HibernateException: No Session found for current thread
      org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
      org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
      com.corrisoft.air.db.HibernateDAO.getCurrentSession(HibernateDAO.java:34)
      com.corrisoft.air.db.HibernateDAO.create(HibernateDAO.java:54)
      com.corrisoft.air.service.impl.PersonServiceImpl.createPerson(PersonServiceImpl.java:44)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:597)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy35.createPerson(Unknown Source)
      com.corrisoft.air.ws.RememberNameController.handleRequestInternal(RememberNameController.java:50)
      org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:154)
      org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  </code></pre>
  
  <p>Here's my services.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/aop
                          http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                          http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-4.0.xsd
                          http://www.springframework.org/schema/tx
                          http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"&gt;
  
      &lt;bean id="personService" class="com.corrisoft.air.service.impl.PersonServiceImpl" init-method="init"&gt;
          &lt;property name="personDAO" ref="personDAO"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- the transactional advice (what happens; see the &lt;aop:advisor/&gt; bean below) --&gt;
      &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;
          &lt;!-- the transactional semantics... --&gt;
          &lt;tx:attributes&gt;
              &lt;!-- all methods starting with get are read-only --&gt;
              &lt;tx:method name="retrieve*" read-only="true"/&gt;
              &lt;!-- other methods use the default transaction settings (see below) --&gt;
              &lt;tx:method name=""/&gt;
          &lt;/tx:attributes&gt;
      &lt;/tx:advice&gt;
  
      &lt;!-- ensure that the above transactional advice runs for any execution
          of an operation defined by the serviceUpdateOperations --&gt;
      &lt;aop:config&gt;
          &lt;aop:pointcut id="serviceUpdateOperations"
                        expression="execution(* com.corrisoft.air.service.impl.*.*(..))"/&gt;
          &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="serviceUpdateOperations"/&gt;
      &lt;/aop:config&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And my data.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
      &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
          &lt;property name="driverClass" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="jdbcUrl" value="jdbc:mysql://localhost/example"/&gt;
          &lt;property name="user" value="root"/&gt;
          &lt;property name="password" value="ncc-1701"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="packagesToScan" value="com.corrisoft.air.model" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;value&gt;
                  hibernate.hbm2ddl.auto=create
                  hibernate.dialect=org.hibernate.dialect.MySQLDialect
              &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name = "sessionFactory" ref = "sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="persistenceExceptionTranslationPostProcessor"
            class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"&gt;
      &lt;/bean&gt;
  
      &lt;!-- DAOs --&gt;
      &lt;bean id="personDAO" class="com.corrisoft.air.db.hibernate.PersonHibernateDAO"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Since I saw that many of these requested an @Transactional on my service, I tried it for good measure. Didn't help.</p>