In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand the Session of the Hibernate expansion cycle". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the Session of the Hibernate expansion cycle".
A single Hibernate Session instance and all persistent object instances associated with it are used for the entire conversation, which is called session-per-conversation. Hibernate checks the version of the object instance during synchronization and throws an exception if concurrent modifications are detected. It is up to the developer to decide whether or not to catch and handle this exception (the usual choice is to give the user an opportunity to merge changes or resume a business conversation without dirty data).
While waiting for user interaction, Hibernate Session disconnects the underlying JDBC connection. This approach is efficient from a database access point of view. The application does not need to care about version checking or the reassociation of the detached object instance, nor does the application need to load the read object instance in each database transaction.
/ / foo is an instance loaded earlier by the old session Transaction t = session.beginTransaction (); / / Obtain a new JDBC connection, start transaction foo.setProperty ("bar"); session.flush (); / / Only for last transaction in conversation t.commit (); / / Also return JDBC connection session.close (); / / Only for last transaction in conversation
The foo object knows in which Session it was loaded. Opening a new database transaction in an old session causes session to obtain a new connection and restore session functionality.
Commit the database transaction so that session is disconnected from the JDBC connection and return the connection to the connection pool. To force a version check on your unupdated data after reconnecting, you can call Session.lock () with the parameter LockMode.READ for all objects that may have been modified by other transactions. You don't need to lock any data you are updating.
Usually you will set FlushMode.NEVER on the extended Session, so only * a database transaction cycle will actually send the changes that occurred in the entire conversation to the database. Therefore, only this * database transaction will include the flush () operation, and then close () the session at the end of the entire conversation.
This mode is problematic if the Session is too large to be saved while the user is thinking. For example, a HttpSession should be as small as possible.
Because Session is a first-level cache and holds all loaded objects, we should only use this strategy in those small amounts of request/response. You should use only one Session for a single conversation, because it will soon show dirty data.
Note:
Early versions of Hibernate required explicit disconnec and reconnect of Session. These methods are now out of date, and opening and closing transactions will have the same effect.
Also note that you should keep the Session disconnected from the database off to the persistence layer. In other words, in a three-tier environment, use a stateful EJB session bean to hold the Session instead of passing it to the web layer (or even serializing it to a separate layer) and storing it in the HttpSession.
Extending the session schema, or one session per conversation (session-per-conversation), can be more difficult in conjunction with automatically managing the current session context. You need to provide your own CurrentSessionContext implementation. See Hibernate Wiki for an example.
Thank you for reading, the above is the content of "how to understand the Session of the Hibernate expansion cycle". After the study of this article, I believe you have a deeper understanding of how to understand the Session of the Hibernate expansion cycle, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.