Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand Hiberate3 Session caching

Shulou Source: shulou.com Published: 2022-06-02 12:07:07 09月28日 Update

This article introduces you how to understand Hiberate3 Session cache, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Hiberate3 has a lot to learn, and here we focus on Hiberate3 Session caching, including the differences between List () and iterate queries.

1.Hiberate3 Session cache, which is bound to session. Its life cycle is the same as that of session. Session destroys, it also destroys at the same time; manage first-level cache, first-level cache cannot be cancelled, use two methods to manage, clear (), evict ()

two。 The two session cannot share a first-level cache because it will accompany the creation and destruction of the session lifecycle

3.Hiberate3 Session caching is entity-level caching, which is used only when querying the object level. If HQL and SQL are used at the query attribute level, first-level caching is not used! Remember!

If 4.iterate query uses cache, it will issue SQL and HQL statements to query Id, but will not issue query entities. After query, it will put the corresponding entities in the cache. Some entity queries will be queried from the cache if there are in the cache, but will still issue SQL and HQL statements to query id. If it is not in the cache, it will be queried in the database, and then the queried entities will be put into the cache one by one, so there will be Number1 problems.

The difference between 5.List () and iterate queries:

Using iterate,list to query entity objects * Number1 problems can occur by default when using query.iterate queries. The so-called Number1 query issues a sql statement when querying. 1: first issue a sqlN that queries the id list of objects:

According to the id list to the cache query, if there is no matching data in the cache, then the corresponding sql statement list and iterate will be issued according to id.

List issues a sql statement every time, and list puts data into the cache without using the data in the cache. Iterate: by default, iterate makes use of cached data, but if there is no data in the cache, it can cause Nation1 problems.

Both 6.Get () and load (), iterate methods use first-level caching

The 7.hiberate3 session stored procedure is as follows:

For example, object object

◆ Session.save (object)

At this time, the data will not be put into the database, but will be put into the session cache first. There is no corresponding record in the database.

◆ session.flush (); has just issued SQL and HQL statements, and there are corresponding records in the database.

But the database cannot be found with select, which has something to do with the transaction level of the database.

◆ Session.beginTrransaction (). Commit ()

Things can be queried after they have been submitted.

◆ Session.flush () statement but why not write it, because commit () calls flush () by default

On how to understand Hiberate3 Session cache to share 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.

Tags: Cache query data statement database entity object level problem two things content cycle situation method time more life help management Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Linux vpn MariaDB