Javatpoint Logo
Javatpoint Logo

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.javatpoint.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




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA