Java examples for javax.persistence:EntityManager
add AbstractEntity to EntityManager
import java.io.Serializable; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; public class Main{ public static void add(AbstractEntity entity, EntityManager em) { if (entity == null) return; if (em == null) throw new IllegalArgumentException(); if (!em.isOpen()) throw new IllegalArgumentException(); try {/*from w w w .j a v a 2 s . c o m*/ em.getTransaction().begin(); em.persist(entity); em.getTransaction().commit(); } catch (Exception e) { throw e; } finally { em.close(); } } }