title: Cannot reopen transaction using EntityManger
body: <p>i'm trying to open transaction twice using one EntityManager:</p>
  <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory(&quot;HelloWorldPU&quot;);
          EntityManager em = emf.createEntityManager();
  
          Message message0 = new Message();
          message0.setText(&quot;Hi!!&quot;);
          em.getTransaction().begin();
          em.persist(message0);
          em.getTransaction().commit();
          em.close();
          
          Message message1 = new Message();
          message1.setText(&quot;Bye!!&quot;);
  
          System.out.println(&quot;i'm here&quot;);
          em.getTransaction().begin();
          em.persist(message1);
          em.getTransaction().commit();
          em.close();
  </code></pre>
  <p>and get an exception:</p>
  <blockquote>
  <p>i'm here</p>
  <p>Exception in thread &quot;main&quot; java.lang.IllegalStateException: org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl@31e4bb20 is closed</p>
  </blockquote>
  <p>My guess is: it is not possible to get another transaction from closed EntityManager. However <a href="http://download.oracle.com/otndocs/jcp/persistence-2_1-edr-spec/index.html" rel="nofollow noreferrer">JPA Spec</a> says:</p>
  <blockquote>
  <p><code>EntityManager.close</code> method closes an entity manager to release its persistence context and other resources. After calling <code>close</code>, the application must not invoke any further methods on the  <code>EntityManager</code> instance except for <code>getTransaction</code> and <code>isOpen</code>, or the <code>IllegalStateException</code> will be thrown. If the <code>close</code> method is invoked when a transaction is active, the persistence context remains managed until the transaction completes.</p>
  </blockquote>
  <p>Could someone explain where i'm wrong? doesn't possibility of invoking <code>getTransaction</code> mean that i can use this transaction and ivoke transaction's methods?</p>
  <p>Thank you.</p>
  <p>UPDATE</p>
  <p>Thanks for the answers, these are most helpful for me:</p>
  <p>1:</p>
  <blockquote>
  <p>You can use the EntityManager until you call close, yes. There is no
  &quot;reopen&quot; method. Creating an EntityManager is a cheap operation – Neil
  Stockton 13 mins ago</p>
  </blockquote>
  <p>2:</p>
  <blockquote>
  <p>You can call getTransaction to check if a transaction is active. Yu
  could also close an EntityManager with an active tx (as the docs
  state) and commit after the close). Hence the fact you can call
  getTransaction. – M. Deinum 9 mins ago</p>
  </blockquote>