8.4.1 Methods provided with EntityManager
The EntityManager provides methods. The typical methods are as follows:
-
persist method (equivalent to SQL INSERT)
The method used to add an entity object that executes new in the application, into the database.
-
find method (equivalent to SQL SELECT)
The method used to search an entity object from the database.
-
remove method (equivalent to SQL DELETE)
The method used to delete an entity object from the database.
The entity objects searched using the find method from EntityManager and the entity objects passed to EntityManager using the persist method are managed by EntityManager. If a field value of an entity object managed by EntityManager is changed, EntityManager automatically detects the change and applies the change to the database table.
With the JPA, an entity object managed by EntityManager is called a managed entity. By default, when a transaction is concluded, the entity is no longer managed by EntityManager. An entity that is no longer managed by EntityManager is called a detached entity.