Home » JPA Deleting an Entity

JPA Deleting an Entity

by Online Tutorials Library

Deleting an Entity

To delete a record from database, EntityManager interface provides remove() method. The remove() method uses primary key to delete the particular record.

JPA Entity Delete Example

Here, we will remove the particular record of the student.

This example contains the following steps: –

  • Create an entity class named as StudentEntity.java under com.tutoraspire.jpa.student package that contains attributes s_id, s_name and s_age.

StudentEntity.java

  • Now, map the entity class and other databases confiuguration in Persistence.xml file.

Persistence.xml

Deletion.java

Output:

After the execution of the program, the student table is generated under MySQL workbench.This table contains the student details. To fetch data, run select * from student query in MySQL.

Before Deletion

JPA Deleting an Entity

After Deletion

JPA Deleting an Entity

Next TopicCollection Mapping

You may also like