update AbstractEntity using EntityManager - Java javax.persistence

Java examples for javax.persistence:EntityManager

Description

update AbstractEntity using EntityManager

Demo Code


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();
        }
    }
}

Related Tutorials