Maven dependencies used all over JPA tutorials same. Please follow "Setting up Project" section to understand about project configuration.
persistence.xml and other code files reused from How to Persist an Entity in data base using JPA?
Each Sample application from download includes SQL file also.

Updating an Entity :

  • Once an entity in the database, Student student = entintyManager.find(Student.class, 1L); this line will retrieve student entity where identifier value is 1.
  • The above line makes the state of Student object “persistent”.
  • Persistent state instances are always associated with persistence-context and transnational.
  • If we are changing persistent State object values those are synchronized automatically with the database while committing the transaction.
To understand JPA entity life cycle completely see this tutorial JPA Entity lifecycle

Persistence transition or state change when EntityManager’s find() called :

Updating Entity Code :

Console Output :

Download Application – (10 KB)