Hibernate delayed loading and lazy attribute configuration. And org. hibernate. lazyinitializationexception

Source: Internet
Author: User

This is one-to-many, that is, one MERs corresponds to multiple orders


The following is one-to-one:


Important configurations:

1. Inverse is the opposite. It means that this association is controlled by the other party, that is, the other party of the queue.

inverse="true"

2. Lazy indicates whether to delay loading. It is loaded only when needed, and does not need to be loaded.

After the session is turned off, we cannot load it any more.

Is common: org. hibernate. lazyinitializationexception

In this case, we set lazy to false.

Lazy has two configuration methods:

1) Configure in sequence-to-one or set:

  <set name="orderses" inverse="true" cascade="save-update" lazy="true">

On one side, lazy has three values: false, true, and extra. The default value is true.

Delayed loading has a great advantage, saving SQL statements.

On the worker side, lazy has three values: false, proxy, and no-proxy. Note that the true option is not available here.

Generally, when querying the region side, it also queries the one side.

2) Configure in class:

Lazy on the class only works for common attributes, and does not work for any set or list, so the set and others need to be written again.




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.