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.