Hibernate Workflow:
1. Read and parse the configuration file
2. Read and parse mapping information, create Sessionfactory
3. Open Sesssion
4. Create Transaction Transation
5. Persistent operation
6. Commit a transaction
7. Close session
8. Close Sesstionfactory
Three state of Bean in hibernate
Hibernate objects are divided into three states: transient (new or instantiated session-independent),
Persistent State (Session association) and Free State (formerly associated with session). Where the persisted object is the PO
, the object of instantaneous state and managed state can be used as VO. (PO should not be used directly as a V-layer) so you should pay attention to three-state conversions in use.
Such as:
During a series of data manipulation, the save or saveorupdate operation can convert an instantaneous state or a free State object into a persistent state, while
The delete or session close, flush, and so on will convert the persistent object associated with the session into a free state.
Hibernate object state and life cycle
The object initialized with the new operator is a transient state (Transient)
(There is no behavior associated with a database table, and as long as the app no longer references those objects, their state is lost and reclaimed by the garbage collection mechanism);
The instantaneous state object passes save (), the saveorupdate will be converted into a persistent state, and the operation of the persistent state object can be synchronized with the database.
The persisted object passes through evict (), close (), clear (), and so on, and so on, while being persisted, but not in the session cache, by
Lock (), update (), and the saveorupdate will be converted to a persistent state. by get (), load (), find (), iterate ()
The object that is obtained is directly a persistent state.
Hibernate workflows and three statuses (interview questions)