MyBatis correlation Query, the number of records queried is inconsistent with the database direct query, how to solve?

Source: Internet
Author: User

<select id= "Finduserinfolistformap" resultmap= "Baseresultmap" >
SELECT p.name, U.u_name,u.company,u.procomany,u.mobile,u.email, R.money
From Iw_user u
Left JOIN Raiseentry R on R.userid=u.id
Left JOIN Project P on R.sourceid=p.projectid
</select>

After careful verification, the attributes in the Baseresultmap are all complete, but the number of record bars returned when the statement executes is inconsistent with queries directly in the database.

But after changing to the following statement, (more than one query field u.id)

<select id= "Finduserinfolistformap" resultmap= "Baseresultmap" >

SELECT u.id, P.name, U.u_name,u.company,u.procomany,u.mobile,u.email, R.money

From Iw_user u

Left JOIN raiseentry R on r.userid=u.id

Left JOIN Project P on r.sourceid=p.projectid </select>

The query results are normal. Baidu has found that some people have encountered this situation (http://www.iteye.com/problems/95931), the solution is:

1) SELECT * From ....

2) Select r.userid,u.id, R.sourceid,p.projectid (include these fields) ...

3) Encapsulate the field you want to query into a Dto object, and in Mapper.xml, define a resultmap,type that points to the Dto object, which is the mapping that requires querying the fields and the Dto object properties.

MyBatis correlation Query, the number of records queried is inconsistent with the database direct query, how to solve?

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.