Java examples for javax.persistence:EntityManager
update AbstractEntity using EntityManager
import java.io.Serializable; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; public class Main{ public static void update(AbstractEntity entity, EntityManager em) { if (entity == null) return; if (em == null) throw new IllegalArgumentException(); if (!em.isOpen()) throw new IllegalArgumentException(); try {// www. j a v a2s.co m em.getTransaction().begin(); em.merge(entity); em.getTransaction().commit(); } catch (Exception e) { throw e; } finally { em.close(); } } }