EntityManager commit Object - Java javax.persistence

Java examples for javax.persistence:EntityManager

Description

EntityManager commit Object

Demo Code


import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Main{
    public static EntityManagerFactory entityManagerFactory = Persistence
            .createEntityManagerFactory("MyInsuranceWS");
    public static <T> boolean commitObject(T object) {

        boolean success = true;
        EntityManager em = entityManagerFactory.createEntityManager();
        try {// w ww  .  jav a2  s.co  m

            em.getTransaction().begin();
            em.persist(object);
            em.getTransaction().commit();
            em.close();
        } catch (Exception e) {
            e.printStackTrace();
            success = false;
        }

        return success;

    }
}

Related Tutorials