title: SessionFactory.getCurrentSession() vs EntityManager.createEntityManager()
body: <p>So I had been working with Hibernate <code>SessionFactory</code> and its <code>getCurrentSession</code> method for inside a transaction for a while now. </p>
  
  <pre><code>Session session = sessionFactory.getCurrentSession();
  </code></pre>
  
  <p>and having it interact with other DAO classes within the same test. Switching to JPA though, can I inject a container managed <code>EntityManagerFactory</code> and then replacing the above with </p>
  
  <pre><code>EntityManager entityManager = myFactory.createEntityManager();
  </code></pre>
  
  <p>and then continue as session interface equivalents in <code>EntityManager</code> in current tests? Performing <code>entityManager.flush()</code> causes </p>
  
  <pre><code>javax.persistence.TransactionRequiredException: no transaction is in progress
  </code></pre>