To execute the persist operation for the entities, invoke the persist method of EntityManager. If the persist method of EntityManager is invoked and the persist processing is cascaded, the entity is managed in the persistence and persistence context of the database.
The following table describes the state of the entity after the persist operation, for each entity state.
Table 6-8 State of the entities in the persist operation
State of the entity | State of the entity after the persist operation |
---|---|
new# | The state changes to managed. The entity changed to managed is added into the database during or before transaction commit or is added into the database as a result of the execution of the flush operation. |
managed | The persist operation is ignored. However, if PERSIST or ALL is specified in the cascade attribute for the relationship from one entity to another entity, the persist operation is propagated to the entities referenced by this entity. |
detached# | If the line corresponding to the entity does not exist in the database, the state changes to managed. If the corresponding line exists, EntityExistsException occurs. |
removed | The state changes to managed. |
# For Cosminexus JPA Provider, when the state of an entity is new or detached, the results of the transition of entity states differ according to whether the data corresponding to the entity exists on the database. Note the following for Cosminexus JPA Provider: