title: Java persistence api not deleting / removing record oracle database 11g XE
body: <p>I successfully created, merged, fetched records using Java Persistence API, but I'm not able to remove a record. I used em.createNativeQuery("Delete ...") and it worked fine, the problem is that I want to use the entity manager to do that. I think the problem could be with the oracle database, because I tried the above code with Derby and it worked fine.</p>
  
  <pre><code> public void destroy(String id) throws NonexistentEntityException, RollbackFailureException, Exception {
      EntityManager em = null;
      Context initCtx = new InitialContext();
      utx = (UserTransaction) initCtx.lookup("java:comp/env/UserTransaction");
      try {
          utx.begin();
          em = getEntityManager();
          //Query query =  em.createNativeQuery("DELETE FROM SERVICIO WHERE SERVICIODESCRIPCION = '"+id+"'");
          //query.executeUpdate();
          Servicio servicio;
          try {
              servicio = em.getReference(Servicio.class, id);
              servicio.getServiciodescripcion();
          } catch (EntityNotFoundException enfe) {
              throw new NonexistentEntityException("The servicio with id " + id + " no longer exists.", enfe);
          }
          em.remove(servicio);
          utx.commit();
      } catch (Exception ex) {
          try {
              utx.rollback();
          } catch (Exception re) {
              throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
          }
          throw ex;
      } finally {
          if (em != null) {
              em.flush();
              em.close();
          }
      }
  }
  </code></pre>