JPA + MYSQL: the query records are the same entity.

Source: Internet
Author: User

In the JPA function, I used createnativequery to execute a query statement. This query statement uses union and left join. After the query result is displayed, the number of records is correct, however, the data of each record is exactly the same, and the query statement executed by the record is put in MySQL for query. The result is correct. Each record is a record, but after JPA is mapped to entity, it becomes the same record with the same number.

Later I found out that because union is used and left join is used, in the select Field List, Id points to a completely identical value, that is, although the queried records are different, but its ID result value is the same !!

Therefore, when JPA maps entity, it is divided into different entities based on the ID. If the IDs are the same, it is considered to be the same record and record the records repeatedly, rather than record the values of other fields separately.

Related Article

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.