The difference between lazy loading and rush loading in Hibernate, and the difference between the Get () method and the load () method in Hibernate

Source: Internet
Author: User


* Lazy loading when loading an entity, it is not immediately loaded from the database, that is, loaded into memory from the database. When loading an entity, the load is immediately queried from the database, and the class associated with it is queried at the same time.

The rush load will be quick, because it has been loaded for us at the first load. Lazy loading is relatively slow, because it does not perform SQL operations until we need to query the door.

The advantage of lazy loading is that the memory is small, the execution speed is slow, the load is fast and the memory is high.

Hibernate's Get () He load () method is very different at the time of execution,

Executing the Get () method will load all the basic data,

While the load () method will only load the id attribute in lazy loading, all the ID attributes, other non-ID attributes of the operation will not be executed, when we need to query the specific data is not really execute SQL operation, because lazy loading is valid in a session, So today we get an error when we close the session, because hibernate tries to send SQL queries through the current session, but finds that the session is closed so that no session exceptions are made.

We can load the mode into an urgent load or do not close the session.



The difference between lazy loading and rush loading in Hibernate, and the difference between the Get () method and the load () method in Hibernate

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.