There can be 4 persistent states:
- When we first create an object it is in transient state.
- If we persist this object it moves to the so called Persisted state.
- If a persisted object is no longer in persistent context then we consider this object as detached. This means that changes to this object are not persistent in the database unless we merge() its state. If no references exist for this object it will be garbage collected but the object will still have a representation in the database.
- The final state is the removed state and an object can get to this state if we call the remove() method or if we remove the reference this object has to a persistent object and the orphan removal is enabled. In this case, once no other references exist for this object, the object will not only be garbage collected but it will also be deleted from the database.
Comments
Post a Comment