How Hibernate works, hibernate

Source: Internet
Author: User

How Hibernate works, hibernate
1. How does Hibernate work and why?

Principle:

1. Read and parse the configuration file

2. Read and parse the ing information and create SessionFactory

3. Open Sesssion

4. Create transaction Transation

5. Persistent operations

6. Submit the transaction

7. Disable Session

8. Disable SesstionFactory

Why:

1. The code for JDBC database access is encapsulated, which greatly simplifies the tedious and repetitive code at the data access layer.

2. Hibernate is a mainstream persistence framework based on JDBC and an excellent ORM implementation. He greatly simplifies the coding of the DAO layer.

3. hibernate uses the Java reflection mechanism instead of the bytecode enhancement program to achieve transparency.

4. hibernate has excellent performance because it is a lightweight framework. The flexibility of ing is excellent. It supports various relational databases, from one-to-one to many-to-many complex relationships.

How does Hibernate delay loading?

1. Implementation of Hibernate2 delayed loading: a) object B) Collection)

2. hibernate3 provides the attribute delayed loading function. When Hibernate queries data, the data does not exist in the memory. When the program actually operates on the data, the object exists in the memory, this achieves delayed loading, which saves the memory overhead of the server and improves the server performance.

3. How does one implement the relationship between classes in Hibernate? (For example, one-to-many and many-to-many relationships)

The relationship between classes is mainly reflected in the relationship between tables. They operate on objects in a city. In our program, all tables and classes are mapped together, they are used in the configuration file named "allow-to-one", "one-to-allow", "allow-to-allow,

4. Talk about the cache mechanism of Hibernate

1. The internal cache exists in Hibernate, which is also called a level-1 cache, which belongs to the application thing-level cache.

2. level 2 Cache: a) Application and cache B) distributed cache conditions: data will not be modified by a third party, the data size is acceptable, the data update frequency is low, the same data is frequently used by the system, and non-critical data c) Implementation of third-party Cache

5. Hibernate query method

SQL, Criteria, objectcomptositionHql: 1. Attribute query 2. parameter query, name parameter query 3. association query 4. Paging query 5. statistical function

6. How to optimize Hibernate?

1. Use bidirectional one-to-Multiple Association instead of unidirectional one-to-Multiple Association

2. flexible use of one-to-multiple associations

3. Replace multiple-to-one instead of one-to-one

4. Configure the object cache without using the set Cache

5. Use Bag for one-to-multiple sets and Set for multiple-to-multiple sets

6. Use explicit polymorphism for inheritance classes

7. Fewer table fields, no more table Association, and secondary cache support

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.