If an entity has been defined, later on instantiated, than the life cycle of the entity begins.
The life cycle of an entity ends with remove() or a detach() (see below) method call.
An entity does not know its state of the current life cycle.
So it cannot be be queried to retrieve it's state.
What states does a JPA entity has in its lifespan?
- transient
As soon as this class is instantiated, it has the state transient, that means it is still a POJO, but
it will not be synchronized with the database.
- persistent
The entity will be synchronized with the database on transaction end(commit() or flush()).
- detached
A detached entity is integrated into the persistence context on calling merge().
A persistent entity can be turned into the state transient with the help of remove(), the corresponding data in the database will be deleted.
No comments:
Post a Comment