In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the three states of persistent objects in Hibernate". In daily operation, I believe many people have doubts about what is the three states of persistent objects in Hibernate. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to answer the doubts of "what is the three states of persistent objects in Hibernate"! Next, please follow the small series to learn together!
As we all know, the life cycle of Java objects begins with the creation of new statements and ends when they are no longer referenced by any reference variables. At the end, the memory they occupy will be reclaimed by the JVM garbage collection mechanism. In Hibernate persistent objects can be divided into three states: transient, persistent, and tube-free.
1. Transient (also called temporary state). Objects in this state have the following characteristics:
◆ Not in the Session cache, not associated with any Session instance.
There is no corresponding record in the database.
2. Persistent: An object in this state has the following characteristics:
◆ In the Session cache, associated with the Session instance.
There is a corresponding record in the database.
3. The detached state is also called free state. Objects in this state have the following characteristics:
◆ Not in the Session cache, not associated with any Session instance.
There is a corresponding record in the database. (Provided that no other Session instance deletes the record).
The three states of persistent objects can be transformed into each other. The specific transformation process is shown in the figure:
New objects such as Student stu = new Student(), are transient objects that exist in isolation in memory, meaning that they carry information and do not have any association with the data in the database.
The save() or saveOrUpdate() method of Session can associate a transient object with the database, and insert the information carried by the transient object into the database through the mapping made by the configuration file. This transient object is converted into a persistent object (the data object queried by using get(),load(), etc. is a persistent object as soon as it appears), and has the same id identifier as the database record (Hibernate automatically assigns the id value to it).
If you use delete() at this point, it becomes a transient object, deleting the database record associated with the object, and the object no longer has any association with the database. When a Session specifies close() or clear(),evict(), persistent objects become detached objects, and although the object id has a database identification value, they are not currently managed by Hibernate persistence layer. It is essentially the same as transient objects, except that it has more id values than transient objects.
The reference to the unmanaged object is still valid, the object can continue to be modified, and when it is re-associated to a new Session, it becomes persistent again (changes made during the unmanaged state are persisted to the database). An out-of-pipe object has a database identifier id, so it can be re-associated with the persistence layer via update(),saveOrUpdate(),lock(), etc.
At this point, the study of "what is a persistent object in Hibernate's three states" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.