title: Spring Hibernate SessionFactory configuration
body: <p>I have a little problem with hibernate.</p>
  
  <p>I have some simple DAO </p>
  
  <pre><code>@Repository
  public class UserDAOImpl implements UserDAO {
  
  @Autowired
  private SessionFactory sessionFactory;
  
  private Session openSession() {
      return sessionFactory.getCurrentSession();
  }
  @Transactional
  public User getUser(String login) {
      List&lt;User&gt; userList;
      Query query = openSession().createQuery("from User u where u.login = :login");
      query.setParameter("login", login);
      userList = query.list();
      if (userList.size() &gt; 0)
          return userList.get(0);
      else
          return null;    
  }
  }
  </code></pre>
  
  <p>here bean configuration for sessionFactory</p>
  
  <pre><code> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&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;
  </code></pre>
  
  <p>If i remove @Transactional anotation from <code>public User getUser(String login)</code> i've got </p>
  
  <pre><code>org.hibernate.HibernateException: No Session found for current thread
  org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
  org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941)
  </code></pre>
  
  <p>where i'm wrog ?</p>