instantaneous (transient): There is no data in the database corresponding to it, more than the scope will be reclaimed by the JVM garbage collector, usually new and not associated with the session object.
Persistent (persistent): There is data in the database corresponding to it, currently associated with the session, and the associated session is not closed, the transaction is not submitted;
The persistent object state changes and the database is affected when the transaction commits (Hibernate detects it).
(When the object is save, the data is persisted, then Obj.set () commits the transaction and hibernate detects the modification of the data.
If the object is not persisted before the object is save (even in a transaction), hibernate cannot detect the data modification without affecting the database (Obj.set) ().
off-tube/free (detached): There is data in the database corresponding to it, but there is no session associated with it; the state of the off-tube object changes, hibernate cannot detect.
Hibernate Object three states, conversion diagram :
Commit() closes session
interview diagram : What happens if an object is judged ?
The main basis is : 1. See if the object is in session, 2, see if there are any corresponding records in the database.
Summarize:
transient State : no session Management , and no corresponding record in database
Persistent State : has session Management and is logged in the database
off -state/ Free State: There is no session Management, but there are records in the database .
Hibernate (vi) __ three states of objects