Things in Hibernate are on the business floor.

Source: Internet
Author: User
In http://blog.51cto.com/13579086/2074232 This article, we describe two approaches to how connection from the business layer to the persistence layer

In Hibernate, things are also tied to local variables on the current thread in the business layer, and the persistence layer is taken from the local variables of the current thread

Hibernate 5 itself provides three ways to manage Session objects
The lifetime of the Session object is bound to the local thread
The life cycle of the Session object is bound to the JTA transaction
Hibernate Delegate program manages the life cycle of the Session object

In Hibernate's configuration file, the Hibernate.current_session_context_class attribute is used to specify the session management method, and the optional values include
Thread:session the life cycle of an object with local thread bindings
jta*: The lifecycle of a Session object and the JTA transaction binding
Managed:hibernate delegate program to manage the life cycle of Session objects

Bindings are part of the pass we need to add a profile to the main configuration file

    <property name="hibernate.current_session_context_class">thread</property>

How to get the session from the current thread
Sessionfactory.getcurrentsession ();

Things in Hibernate are on the business floor.

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.