title: update using JPA
body: <p>I m using glassfish v2 and persistence in a web application.</p>
  
  <p>I m calling persistence codes using a normal java class file inside a web Application</p>
  
  <p>I can select easily using this code: -</p>
  
  <pre><code>   @PersistenceUnit
  public EntityManagerFactory emf;
  EntityManager em;
  
  
  public List fname (String id) {
      String fname = null;
      List persons = null;
      //private PersistenceManagerFactory persistenceManagerFactory;
  
      try {
          emf = Persistence.createEntityManagerFactory("WebApplicationSecurityPU");
  
          em = emf.createEntityManager();
          persons = em.createQuery("select r from Roleuser r").getResultList();
  
          int i=0;
          for (i=0;i&lt;persons.size(); i++)
              System.out.println("Testing n "+ i +" " + persons.get(i));
  
      } catch(Exception e) {
          System.out.println("" + e);
      }
      finally {
          if(em != null) {
              em.close();
          }
      }
      return persons;
  }
  </code></pre>
  
  <p>I want to update using JTA as the persistence.xml file has
  transaction-type="JTA"</p>
  
  <p>When i try using update using this code i get a nullPointerException without any traces in the log </p>
  
  <pre><code>     @PersistenceUnit
  public EntityManagerFactory emf;
  EntityManager em;
  Context context;
  @Resource
  private UserTransaction utx;
  
  public List fname (String id) {
  
      String fname = null;
      List persons = null;
  
  
      try {
          emf = Persistence.createEntityManagerFactory("WebApplicationSecurityPU");
  
          utx.begin();
          em = emf.createEntityManager();
  
          int m = em.createQuery("update Roleuser r set r.firstName = 'Jignesh I' where r.userID=9").executeUpdate();
  
          utx.commit();
  
  
      } catch(Exception e) {
          System.out.println("" + e);
      }
      finally {
          if(em != null) {
              em.close();
          }
      }
      return persons;
  }
  </code></pre>
  
  <p>Any help</p>
  
  <p>Thanks</p>
  
  <p>Pradyut</p>