Is there more than one thread in hibernate that accesses the same session at the same time?

Source: Internet
Author: User


Since Sessionfactory.opensession () each get a different object, there is no multi-threaded access to the problem, why do ThreadLocal and other things to solve the so-called problem.

If this is the problem, then I understand that: "Multi-threaded access violation" is not the first problem to be solved, but to solve another problem arising from the problem. The real solution is "how to get a Session object for database operations at any time in the process of processing the program."

A request by the servlet process, will penetrate a lot of layers of code, with parameter transmission is obviously inconvenient, so to be able to "always get", but at the same time hope that the whole process is the same session object, so as to facilitate transaction control requirements. So what to do. Both "Singleton" and "global variables" can achieve this goal, but there will be a "multi-threaded access violation" issue. So there's a way to ThreadLocal like "global variables."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.