4.openSession (), Getcurrentsession () and session context

Source: Internet
Author: User

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

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.