132
Update an Entity
JPA allows us to change the records in database by updating an entity.
JPA Entity Update Example
Here, we will update the age of a student on the basis of primary key.
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
- Create a persistence class named as UpdateStudent.java under com.tutoraspire.jpa.update package to persist the entity object with data.
UpdateStudent.java
Output:
Next TopicJPA Deleting an Entity