Hibernate Performance Optimization

Source: Internet
Author: User

Hibernate is a lightweight encapsulation of JDBC, so in many cases, the performance of Hibernate is lower than that of directly using JDBC to access the database. However, with the correct methods and policies, the efficiency of using Hibernate is very close to that of using JDBC directly, in some cases, the execution efficiency may be higher than that when JDBC is used.

When optimizing the performance of Hibernate, you need to consider the following aspects:

Database Design adjustment.

HQL optimization.

Correct use of APIS (for example, selecting different sets and querying APIs based on different service types ).

Master configuration parameters (log, query cache, fetch_size, batch_size, etc ).

Ing file optimization (ID generation policy, level-2 cache, delayed loading, and association optimization ).

Level 1 Cache Management.

There are also many unique policies for level-2 caching.

Transaction control policy.

Data Query performance is often the main factor affecting the performance of an application system. The impact on query performance involves various stages of system software development. For example, good design, correct query methods, and proper caching are conducive to the improvement of system performance.

The improvement of system performance to all aspects of the system is a balanced process, which must be considered at all stages of the application. In addition, the system performance can be gradually improved only by constantly adjusting and optimizing the development and operation processes.

Considerations in the design phase

A good database structure is conducive to the improvement of system performance. The database with a good structure is not simply a database structure that meets the database design paradigm. This is because the database designed according to the database paradigm can only be said to be the best in terms of structure, there is no redundant data and other issues, but not necessarily the best performance in the production process. Sometimes adding data redundancy appropriately increases the difficulty of data maintenance, but it can greatly simplify business queries and improve the efficiency of data retrieval.

When using Java to access the database, there is another problem, that is, the contradiction between the Object-Oriented Java language and the relational database. There must be an issue of mutual conversion between the two. Whether the problem can be correctly handled is also an important factor affecting system performance.

Based on the above questions, the following three factors should be taken into account in the database design stage.

Java Modeling

When creating a Java object model, you must consider the convenience of database persistence. The created Java object model should be easily stored by the Data style = "COLOR: #000000 "href =" http://storage.it168.com/"target = _ blank> storage, and the simpler the structure of the table in the database, the better.

Database Structure

When designing the database structure, you should also consider whether it can be easily expressed using Java objects. This is not a simple table that corresponds to a direct conversion of an object. More importantly, the converted Java object should be able to describe the relationship between data.

Therefore, in the design stage, Java objects and database structures should be comprehensively considered, that is, they can be considered in two directions. After all, they are not the product of an era, the design results should strike a balance between the two. Although neither party can achieve the optimal performance, it cannot cause a poor structure of the other party. Like a bucket containing water, the shorter Board determines the capacity of the bucket.

Business Requirements

The first two factors are purely technical considerations. In the design process, it is more important to closely follow the business needs. This is because any software system is business-centric, so the system design is no exception. In the design stage, we should consider the convenience of business implementation and the efficiency of execution. A good structure design not only makes the implementation of business functions very easy, but also avoids many complicated operations and can improve the system performance.

The design phase is the foundation of the entire application system development, and its impact on software is second only to the grasp of system requirements. Therefore, there should be an overall consideration of the entire software system in the design phase. The specific design mentioned here is only a small part of the design phase, and comprehensive consideration of many factors can achieve better performance.

 

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.