title: entityManager.getTransaction().rollback() detaches entities?
body: <p>I have the following piece of code:</p>
  
  <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory("test")
  EntityManager entityManager = emf.createEntityManager()
  User user = entityManager.find(User.class, 0);
  entityManager.getTransaction().begin();
  entityManager.getTransaction().rollback();
  entityManager.refresh(user);
  </code></pre>
  
  <p>This throws an IllegalArgumentException on the fourth line saying "Entity not managed". If I change the third line to <code>.commit()</code> instead of <code>.rollback()</code>, everything seems to work fine. </p>
  
  <p>What is going on here? Can I prevent this from happening?</p>
  
  <p><strong>UPDATE:</strong> @DataNucleus is directing me towards PersistenceContext. How do I change the persistence context in my code?</p>