Hibernate's delayed loading, a sharp dual-side knife

Source: Internet
Author: User

Delayed loading is the culprit ".

I sometimes find that the query speed is very slow. I found that I didn't enable delayed loading, causing recursive data to be loaded in.

If I add delayed loading, many pages will not be available, and code-level Recursive delayed loading data reading must be performed in the program.

The policies involved here are too troublesome.

For those with few associations and low levels, it's okay to use them. Once there are too many layers, I 'd rather give up object-oriented instead of simply using a table and an object policy, save all fields.

I would rather read other associated data. After all, there is a buffer, and the speed is not significantly affected. In addition, the performance of a single table is excellent.

 

There is also something about opensessioninview that can solve this problem, but in fact, it is a silly decision to solve delayed loading.

 

There is nothing to discuss about when the usage is small. It doesn't matter how to do it.

 

1. For small data volumes, I 'd rather let them load without delay so that database resources can be released as soon as possible, especially some locks.

2. For large data volumes, I think we need a special class to save the operation results so that it only returns what we need, rather than loading with any delay. For example, we only use the customer's name for an order query, and there is no need to delay loading other customer information.

 

 

Different requirements, different technologies, and ORM such as Hibernate bring us a lot of convenience, but we should never think of it as a "golden oil". In the key aspect that affects performance, don't forget our most basic database operations.

 

 

 

 

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.