title: Cannot get @Transactional and Hibernate 4 to work together
body: <p>I'm trying to get Hibernate 4 and Spring Transactions to play together.  At this point, I'm just trying to get a Hibernate setup that works.</p>
  
  <p>Here's the method called.  When I call it, I get </p>
  
  <pre><code>"org.hibernate.HibernateException: createQuery is not valid without active transaction"
  
  
  
  @Autowired
  SessionFactory sessionFactory;
  
  @Transactional
  public SecurityUserDO findSecurityUser(String email)
  {
      Session session = sessionFactory.getCurrentSession();
  
      Query query = session.createQuery( "from SecurityUserDO where email = :email" );
      query.setString( "email", email );
      return (SecurityUserDO) query.uniqueResult();
  }
  </code></pre>
  
  <p>Here's the config:</p>
  
  <pre><code>&lt;!-- use annotations to find beans in this package --&gt;
  &lt;context:annotation-config/&gt;
  &lt;context:component-scan base-package="com.jelli.phoenix.model" /&gt;
  
  &lt;!--  Default session factory. Requires a dataSource bean to be defined in another config.
  This works with a embedded data source for integration test setup. For real deployment
  the datasource should be a c3p0 pool. --&gt;
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" autowire="byName"
       depends-on="dataSource"&gt;
      &lt;property name="configLocation"&gt;    
          &lt;value&gt;
              classpath:hibernate.cfg.xml
          &lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
  
              &lt;!-- Database connection settings --&gt; 
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
  
              &lt;!-- Caching --&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_second_level_cache"&gt;false&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_query_cache"&gt;false&lt;/prop&gt;
  
              &lt;!-- Performance Settings --&gt; 
              &lt;prop key="hibernate.jdbc.batch_versioned_data"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.use_streams_for_binary"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.max_fetch_depth"&gt;1&lt;/prop&gt;
  
              &lt;!-- When SQL is logged, pretty-print it --&gt; 
              &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
          &lt;/props&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;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Use @Transaction annotations for managing transactions  --&gt;    
  &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>The datasource is specified in another file.</p>
  
  <p>I've read every post I could find on this.  Several said to remove the </p>
  
  <pre><code>"&amp;lt;prop key="hibernate.current_session_context_class"&amp;gt;thread&amp;lt;/prop&amp;gt;", 
  </code></pre>
  
  <p>but that causes the <code>getCurrentSession()</code> to fail.</p>