Hibernate workflows and three statuses (interview questions)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.