Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the life cycle of Hibernate entity objects

Shulou Source: shulou.com Published: 2022-06-02 08:00:09 10月02日 Update

This article introduces the knowledge of "what is the life cycle of Hibernate entity objects". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Life cycle of Hibernate entity object

Three states of solid object

Transient (Free State)

The so-called Transient, that is, entity objects exist freely in memory and have nothing to do with the records in the database.

Persistent (persistent state)

The so-called Persistent, that is, the Hibernate entity object is in a state managed by the Hibernate framework. In this state, the reference of the entity object is brought into the Hibernate entity container to manage.

Changes to objects in the Persistent state will be persisted to the database by Hibernate. In short, if an entity object is associated with a Session instance and is within the validity period of the corresponding Session, it will be in the Persistent state.

Detached (free state)

Objects in Persistent state are in Detached state after their corresponding Session instances are shut down. There is a corresponding record in the database. At the same time, the three states can be converted to each other.

Recognition of Hibernate entity objects

◆ entity identity (Data Identity)

◆ reference comparison (=)

◆ content comparison (equals)

From the point of view of the station database, we believe that in a database table structure, the primary key can uniquely determine a record, then the entity objects with the same primary key are considered to be equal. In Hibernate, this rule also holds.

That's all for "what is the life cycle of a Hibernate entity object?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Object entity state data database cycle life content freedom instance more knowledge management practical effective successful learning next memory at the same time dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Huawei MySQL Microsoft