title: Inserting in my JPA using entity manager native query
body: <p>I am trying to insert a data in my database, i am using JPA in my project. </p>
  
  <p>This is what my bean looks like.</p>
  
  <pre><code>@PersistenceContext
  EntityManager em;
  
      em.createNativeQuery("INSERT INTO testtable ('column1','column2') VALUES ('test1','test2')").executeUpdate();
  </code></pre>
  
  <p>myfacade:</p>
  
  <pre><code>@Stateless
  public class TestFacade extends AbstractFacade&lt;Test&gt; {
      @PersistenceContext(unitName = "TEST2PU")
      private EntityManager em;
  
      @Override
      protected EntityManager getEntityManager() {
          return em;
      }
  
      public TestFacade() {
          super(Test.class);
      }
  </code></pre>
  
  <p>i get an error:</p>
  
  <pre><code>javax.persistence.TransactionRequiredException: executeUpdate is not supported for a Query object obtained through non-transactional access of a container-managed transactional EntityManager
  </code></pre>
  
  <p>and if i dont use <code>@PersistenceContext for EntityManager</code></p>
  
  <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory("TEST2PU");
  EntityManager em = emf.createEntityManager();
  em.createNativeQuery("INSERT INTO testtable ('column1','column2') VALUES ('test1','test2')").executeUpdate();
  </code></pre>
  
  <p>this is my error:</p>
  
  <pre><code>javax.persistence.TransactionRequiredException: 
  Exception Description: No externally managed transaction is currently active for this thread
  </code></pre>
  
  <p>note: really need to use native query for this.</p>