Opensession () open a new session each time, use Opensession (), remember Close () off
Getcurrentsession () in the session context (Hibernate configuration file Current_session_context_class has set) to find the session, if any, then return to the session, Otherwise, a new session will be created. You do not need to call Close (), and the transaction commit is automatically closed. Opensession () and getcurrentsession () cannot be mixed!
Session context is set in Hibernate configuration file (hiberbate.cfg.xml), <property name= "Current_session_context_class" >thread/jta </property>
Transactions can be easily divided into two types: connection transactions and JTA transactions.
Thread is a connection object that manages transactions, does not manage distributed transactions, and belongs to connection transactions
JTA (Java Transaction API) can manage distributed transactions. It requires multiple connection objects to interact with different database systems, at which point JTA uses a third-party transaction manager (transaction manager) to manage different connection transactions uniformly.
4.openSession (), Getcurrentsession () and session context