There are 3 types of Hibernate objects: Transient (Transient), persistent (persistent), and off-state (Detached). Objects that are in persistent state are also known as PO (Persistence object), and instantaneous and de-tube objects are also known as VO (Value object).
1. Instantaneous state
A Java object that opens up memory space by the new command,
For example: Thinksoar Thinksoar = new Thinksoar ("name", "Brother side");
If the object is not referenced by a variable, it will be reclaimed by the Java virtual machine.
Instantaneous objects exist in memory, it is the carrier that carries the information, does not have any relation with the database data, in Hibernate, the instantaneous object can be associated with the database through the session's save () or Saveorupdate () method, and the data corresponding to the inserted database , the instantaneous object is transformed into a persisted object.
2. Persistent state
The object in that state has a corresponding record in the database and has a persistent identity. In the case of Hibernate's Delete () method, the corresponding persistent object becomes instantaneous, because the corresponding data in the database has been deleted, and the object is no longer associated with the database's record.
When a session executes close () or clear (), evict (), the persisted object becomes a de-tube object, at which point the persisted object becomes a de-tube object, while the object has a database recognition value, but it is not under the management of Hibernate persistence layer.
Persistent objects have the following characteristics:
1;. Associated with the session instance;
2;. There is a record associated with it in the database.
3. Off-Pipe State
When the session associated with a persisted object is closed, the persisted object is turned into a de-tube object. When the off-tube object is re-associated to the session, it is again transformed into a persistent object.
The de-tube object has the recognition value of the database and can be transformed into a persistent object by means of update (), Saveorupdate () and so on.
The off-pipe object has the following characteristics:
1;. Essentially the same as an instantaneous object, when no variable references it, the JVM reclaims it at the appropriate time;
2;. A database record identification value is more than an instantaneous object.
3 states of objects in Hibernate: Transient state, persistent state, and off-tube state