Association of objects in Mapper.xml

Source: Internet
Author: User

The Association of objects, especially Manytoone, has two ways: send an extra SQL to query and inline the way

Send an extra SQL: When I use this associated object, I send an extra SQL to query the associated object, and then set it inside the object, which can easily cause n+1 problems.

Inline mode: In this SQL directly connected to the object of the table to join in, the need to query the information all out, and then directly in the Resultmap to assemble the associated objects, so you can avoid n+1 problems, but will cause the performance loss of the connection

Selection principle:

If the associated object is to be displayed in the list, the performance loss associated with the table can be caused directly by using inline

If you want to view this object, then choose how to send an extra SQL query, but it will cause n+1 problems

Which way do you choose?

Choose to send an extra SQL

Because the borrower's information is not displayed in the list, but when we are going to look at the borrower's information, when we are going to check out the details of his loan, we will go to see his information, this property to see an object is displayed.

The notation of association in Mapper.xml

Using the Send extra SQL query, the following SQL statement does not change

The question of optimistic locking

N+1 problem, online search for resources

Association of objects in Mapper.xml

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.