|
Answer» Key states that an entity might be in:
- New / Transient: An object is instantiated but not yet associated with an Entity Manager and has no representation in the database.
- Managed / Persisted.
- DETACHED: Detached entity objects are objects in a special state in which they are not managed by any EntityManager but still represent objects in the database. Detached objects are often returned from a persistence tier to the web layer where they can be displayed to the end-user in some form. Changes can be made to a detached dobject, but these changes won't be persisted to the database until the entity is reassociated with a persistence context (the entity is merged back to an EntityManager to become managed again).
- Removed.
- The merge method's major TASK is to transfer the state from an unmanaged entity (passed as the argument) to its managed counterpart WITHIN the persistence context.
- merge deals with both new and detached entities. Merge causes either INSERT or UPDATE operation according to the sub-scenario (on the one hand it is more robust, on the other hand this robustness needn't be required.)
- persist always causes INSERT SQL operation is executed (i.e. an exception may be thrown if the entity has already been INSERTED and thus the PRIMARY key violation happens.)
Key states that an entity might be in:
|