/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package roseindia;

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

/**
 *
 * @author Administrator
 */
public class JPADelete {
    public static void main(String arg[]){
        EntityManagerFactory emf=Persistence.createEntityManagerFactory("netjpa");
        EntityManager em=emf.createEntityManager();
        try{
            EntityTransaction entr=em.getTransaction();
            entr.begin();
            Query query=em.createQuery("DELETE FROM Student st WHERE st.id= ?1");
            query.setParameter(1, 1);
            int deleteRecord=query.executeUpdate();
            entr.commit();
            System.out.println(deleteRecord+" are deleted.");
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
        }
        finally{
            em.close();
        }
    }

}
