Share on Google+Share on Google+

JPA delete data

In this section we will show you how to delete the persistent unit using JPA api.

JPA delete data


In this section we will show you how to delete the persistent unit using JPA api.

JPA provide remove(Object) to remove the object from the persistence store. To remove the object, we need to first find the object and then remove the object using remover(Object) method of JPA api.

Follow the following steps to create and run the example code:

Create a "" file.

Put the following text in "" file.

Delete code:

package roseindia;

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

* @author Administrator
public class JPADelete {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub

EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");
EntityManager em = emf.createEntityManager();
Student stud1 = em.find(Student.class,1);
catch(Exception e){


Run it and get the output in "Console window" of eclipse.

Check it in MySQL.



Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JPA delete data  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image