Hibernate session details

Source: Internet
Author: User
 

Sesison interface is the most important persistence manager in hibernate. It can perform basic CRUD operations, execution condition queries,Transaction ControlAnd the lifecycle of the Persistent Object.

Single thread, non-shared object. Threads are not secure. When designing the software architecture, avoid multiple threads sharing the same session instance.

Session instances are lightweight, and they do not need to consume too much resources for creation or destruction. You can assign a session instance for each request to create and destroy the session instance in time during each request.

Session has a cache that stores the objects loaded by the current unit of work. The session cache is called the first cache of hibernate.

Session Basic Methods: Save (), get (), load (), delete (), update (), saveorupdate (), merge ();

1. Save (): assign a unique oid to the instantaneous object and add it to the cache of the current session to make it a persistent object,

2. Get (): returns a persistent instance based on the specified oid. First, check whether this OID indicates persistence object exists in the current session cache. If it does not exist, check the second-level cache. If it does not exist, retrieve it from the database table until it is found to return!

3. Load (): First, check whether the persistence instance of this identifier OID exists in the current session cache. If no secondary cache exists, if no proxy object exists, the proxy object is returned (the database is not checked );

4. Delete (): persists the input instance, and then runs the delete statement in the session plan;

5. Update (): add the reattached object to the session cache and change it to a persistent object. Then, execute the update statement when clearing the session cache!

6. saveorupdate (): hibernate automatically checks the status of the current session. If persistence occurs, save () is executed, and update () is executed for hosting ();

7. Merge (): Copies the status of the incoming instance to a persistent instance with the same identifier and returns the instance!

Transaction Control: Session. begintransaction (), enable transaction;

Session. Commit (), submit the transaction:

 

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.