Ejemplo n.º 1
0
  public Long save(BaseEntity instance) {
    if (instance.getId() == null) {
      em.persist(instance);
    } else {
      instance = em.merge(instance);
      em.flush();
    }

    return instance.getId();
  }
Ejemplo n.º 2
0
  public void remove(BaseEntity instance) {
    if (em.contains(instance)) {
      em.remove(instance);
    } else {
      BaseEntity persistentInstance = em.find(instance.getClass(), instance.getId());

      if (persistentInstance != null) {
        em.remove(persistentInstance);
      }
    }
  }