title: Access SessionFactory from Spring Boot Application
body: <p>I am trying to get access to the Hibernate session factory but am getting the following error at the line mentioned.</p>
  
  <pre><code>No CurrentSessionContext configured!
  </code></pre>
  
  <p>code</p>
  
  <pre><code>@Service
  @Transactional
  public class GenericSearchImpl implements GenericSearch {
  
      @Autowired
      private EntityManagerFactory entityManagerFactory;
  
      @Override
      @SuppressWarnings("unchecked")
      public &lt;T&gt; List&lt;T&gt; search(final Class&lt;T&gt; type, final String[] criteriaList, final int page, final int perPage) {
          Session session = getSession();
          ...
      }
  
      public Session getSession() {
          final HibernateEntityManagerFactory emFactory = (HibernateEntityManagerFactory) entityManagerFactory;
          final SessionFactory sessionFactory = emFactory.getSessionFactory(); 
          return sessionFactory.getCurrentSession(); //ERROR No CurrentSessionContext configured!
  
            //This worked but I understand it to be BAD as spring should be managing open sessions.
            //        try {
            //            return sessionFactory.getCurrentSession();
            //        } catch (Exception e) {
            //            return sessionFactory.openSession();
            //        }
      }
  
      ...
  
  }
  </code></pre>
  
  <p>Any idea why? </p>