Hibernate Learning Series-----(2) Hibernate core interface and working mechanism

Source: Internet
Author: User

In the previous Article Hibernate Learning series-----(1) Development environment building, roughly summed up hibernate development environment of the building steps, today, we continue to learn about hibernate knowledge, first talk about the main content of this article:
    1. Configuration class
    2. Sessionfactory interface
    3. Session interface
    4. Transaction interface
    5. Query and Criteria Interface
The following categories are described in detail: Configuration class
    1. Function Description: The configuration class is responsible for managing Hibernate's config information and starting hibernate based on configuration information.
    2. Provide the database link parameter; database connection pool and Object relational file configuration, load configuration information through the Config class and launch hibernate application
    3. Hibernate configuration Method: (1): Using the Hibernate.properties file for configuration, (2) using an XML file configuration, that is, "hibernate.cfg.xml" file, the recommended use of the latter
Sessionfactory interface
    • The Sessionfactory instance corresponds to a data storage source, and our application uses the Sessionfactory instance to get our session object, Sessionfactory features:
      • (1) thread safety, a sessionfactory instance can be shared by multiple threads being applied
      • (2) Heavyweight: A large cache is required to store predefined SQL statements and map data, so if our application uses only one database, simply create a Sessionfactory object to
Session interface
    • The session is also known as the Persistence Manager, which provides CRUD operations related to persistence and is most widely used in hibernate. What are the features of the session interface?
      • (1) Thread is unsafe: it represents one operation of our database, so we should try to avoid multiple threads sharing the same session instance in development;
      • (2) Lightweight: Its destruction and creation do not need to consume too much resources;
      • (3) Hibernate cache: Some objects loaded by the current work unit are stored, each session has its own cache, and the object in the cache can only be used by the current working unit;
      • (4) Sessionfactory object Open: When finished, you should close it in time.
Transaction interface
    • The transaction interface is a transactional interface in Hibernate, which includes the following: The JDBC API, jta,hibernate in the persistence operation (CRUD), must be controlled in the transaction.
Query and Criteria Interface
    • The query and Criteria interface is the querying interface in Hibernate:
      • (1) The query interface wraps a HQL (Hibernate query Language) lookup statement.
      • (2) The criteria interface is more object-oriented and is good at executing dynamic queries.
Hibernate's core interface is basically here, and here's how hibernate works, first:

This picture is better understood, I will not explain.

Hibernate Learning Series-----(2) Hibernate core interface and working mechanism

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.