In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to analyze the working principle and architecture of Hibernate. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Initialization of 1.Hibernate.
Read the configuration information of Hibernate-> create Session Factory
1) create an instance of the Configeration class.
It is constructed by reading configuration information (Hibernate config.xml) into memory.
An Configeration instance represents a collection of mappings from all Java classes of Hibernate to the Sql database.
2) create a SessionFactory instance
Copy all the configuration information in the Configeration object to the SessionFactory cache.
An instance of SessionFactory represents a database store source that is no longer associated with a Configeration object after creation.
Cache: a property of a Java object (usually of some collection type) that takes up memory space.
SessionFactory's cache: Hibernate configuration information. OR maps metadata.
Cache-large: heavyweight objects small: lightweight objects
3) call SessionFactory to create Session
1] users provide their own JDBC connection.
Connection con=dataSource.getConnection ()
Session s=sessionFactory.openSession (con)
2] ask SessionFactory to provide the connection
Session s=sessionFactory.openSession ()
4) manipulate database access through various methods provided by Session interface.
Cache system of Hibernate
First-level cache:
Session has a built-in cache that holds objects loaded by the current unit of work.
Each Session has its own independent cache and can only be accessed by the current unit of work.
Second-tier cache:
External pluggable cache plug-in for SessionFactory. The data can be shared and accessed by multiple Session.
SessionFactory's built-in cache: stores mapping metadata and predefined Sql statements.
The state of the Java object in Hibernate
1. Temporary status (transient)
Characteristics:
1] not in Session cache
2] No object records in the database
How does Java enter the temporary state
1] when you first create an object through a new statement
2] when an object is deleted from the Session cache by calling the delete () method of Session.
two。 Persistence state (persisted)
Characteristics:
1] in Session cache
2] there are object records in the persistent object database.
3] Session will keep the two in sync at certain times.
How does Java enter the persistence state
1] Session's save () makes the temporary-"persistent state"
2] the object returned by the load (), get () method of Session
3] objects stored in the list collection returned by find () of Session
4] Session's update (), saveOrupdate () make free-"persistent"
3. Ionization state (detached)
Characteristics:
1] is no longer in the Session cache
2] the free object changes from the persistent state, and there may be corresponding records in the database.
How does Java enter the persistent state-"free state"
1] close () method of Session
2] the evict () method of Session to delete an object from the cache. Improve performance. Use less.
On how to analyze the working principle and architecture of Hibernate is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.