public Long save(BaseEntity instance) { if (instance.getId() == null) { em.persist(instance); } else { instance = em.merge(instance); em.flush(); } return instance.getId(); }
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); } } }