title: Hibernate exception: No Hibernate Session bound to Thread
body: <p>I am trying to use Hibernate when I attempt to open a Session I get the following Exception</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested 
  exception is org.hibernate.HibernateException: No Hibernate Session bound to thread,        
  and configuration does not allow creation of non-transactional one here
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
      com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
  
  root cause
  
  org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
      org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
      org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
      com.dataart.masternoy.dao.imp.UserDAOImpl.existUserByLoginEmail(UserDAOImpl.java:35)
      com.dataart.masternoy.service.imp.UserServiceImpl.existUserByLoginMail(UserServiceImpl.java:47)
      com.dataart.masternoy.controller.FirstPageController.isValid(FirstPageController.java:46)
      com.dataart.masternoy.controller.FirstPageController.ConfirmRegister(FirstPageController.java:79)
      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.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
      com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
  </code></pre>
  
  <p>here is my config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"        
      default-lazy-init="true"&gt;
      &lt;import resource="applicationContext-services.xml" /&gt;
      &lt;import resource="applicationContext-security.xml" /&gt;
      &lt;import resource="applicationContext-email.xml" /&gt;
      &lt;import resource="applicationContext-social.xml" /&gt;
  
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
      &lt;context:component-scan base-package="com.company.name." /&gt;
      &lt;bean id="validator"
        class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /&gt;
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="prefix" value="/pages/" /&gt;
        &lt;property name="suffix" value=".jsp" /&gt;
        &lt;property name="contentType" value="text/html; charset=UTF-8" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
        &lt;property name="basename" value="messages" /&gt;
        &lt;property name="useCodeAsDefaultMessage" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jacksonMessageConverter"
            class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
      &lt;/bean&gt;
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
        &lt;property name="messageConverters"&gt;
        &lt;list&gt;
          &lt;ref bean="jacksonMessageConverter" /&gt;
        &lt;/list&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Dispatcher Servlet</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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"&gt;
  
      &lt;mvc:annotation-driven /&gt;
      &lt;context:component-scan base-package="com.company.name" /&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;!-- 
       &lt;mvc:view-controller path="/error/" view-name="errors/error" /&gt; 
       &lt;mvc:view-controller path="/403/" view-name="errors/403" /&gt; 
       &lt;mvc:view-controller path="/404/" view-name="errors/404" /&gt; 
       &lt;mvc:view-controller path="/405/" view-name="errors/405" /&gt; 
      --&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Services</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
      default-lazy-init="true"&gt;
  
      &lt;!-- &lt;tx:annotation-driven transaction-manager="txManager" /&gt; --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
        &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt; 
      &lt;bean id="configProperties" class="com.dataart.masternoy.utils.PropertiesUtil"&gt;
        &lt;property name="ignoreUnresolvablePlaceholders" value="true" /&gt;
        &lt;property name="locations"&gt;
          &lt;list&gt;
            &lt;value&gt;classpath:/config.properties&lt;/value&gt;
            &lt;value&gt;classpath:/jdbc.properties&lt;/value&gt;
          &lt;/list&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
        &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
        &lt;property name="url" value="jdbc:mysql://localhost:3306/shop" /&gt;
        &lt;property name="username" value="root" /&gt;
        &lt;property name="password" value="root" /&gt;
      &lt;/bean&gt;
      &lt;bean id="dataSourceNew"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  
          &lt;!-- &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver" /&gt; --&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/shop" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="root" /&gt;
  
      &lt;/bean&gt;
      &lt;bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate"&gt;
          &lt;constructor-arg ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="txManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
      &lt;bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
            lazy-init="true"&gt;
        &lt;property name="dataSource" ref="dataSourceNew" /&gt;
        &lt;property name="packagesToScan" value="com.company.name" /&gt;
        &lt;property name="configLocation"&gt;
          &lt;value&gt;classpath:hibernateConfig.xml&lt;/value&gt;
        &lt;/property&gt;
        &lt;property name="configurationClass"&gt;
          &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
        &lt;/property&gt;
        &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
            &lt;prop key="hibernate.connection.driver_class"&gt;org.hsqldb.jdbcDriver&lt;/prop&gt;
            &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
            &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLInnoDBDialect&lt;/prop&gt;
            &lt;prop key="hibernate.connection.charSet"&gt;UTF-8&lt;/prop&gt;
            &lt;prop key="current_session_context_class"&gt;thread&lt;/prop&gt;
            &lt;prop key="format_sql"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>And serviceImpl</p>
  
  <pre><code>@Service(value = "userService")
  public class UserServiceImpl implements UserService {
  @Autowired
  @Qualifier("UserDAO")
  UserDAO userDAO;
  
  @Transactional
  public void addNewUser(User user) {
      userDAO.insertNewUser(user);
  }
  @Transactional(readOnly = true)
  public User getUserByLogin(String login) {
      return userDAO.selectUserByLogin(login);
  }
  @Transactional(readOnly = true)
  public List&lt;User&gt; getUserList() {
      return userDAO.getUserList();
  }
  @Transactional
  public void removeUserByLogin(String login) {
      userDAO.deleteUserByLogin(login);
  }
  @Transactional(readOnly = true)
  public Boolean existUserByLoginMail(String login, String email) {
      return userDAO.existUserByLoginEmail(login, email);
  }
  @Transactional(readOnly = true)
  public User getUserByID(Long ID) {
      return (User) userDAO.selectUserByID(ID);
  }
  @Transactional(readOnly = true)
  public User getUserByLoginPass(String login, String pass) {
      return userDAO.getUserByLoginPass(login, pass);
  }
  }
  </code></pre>