New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List<X>
in mapper doesn't work when using resultMap
with association
#403
Comments
I think you may need to add one or more https://mybatis.github.io/mybatis-3/sqlmap-xml.html#Result_Maps |
@mches Thanks! It works as expected. I agree that there's no way to know an ID of a row for MyBatis unless I provide it by using But there's a case that rows don't have IDs. Should it work without |
|
@mches Thanks for the details. I tried with But there are some entities having some associations but not having any unique column, right? I don't know MyBatis' internals but it would be nice if Does it make sense? |
As explained in the doc, association works without id, but it is not recommended due to its inefficiency. In your case, the name columns are in the same table, so just map them as nested properties. <resultMap id="complexPersonWithResultMapHavingIdAndAssociation" type="ComplexPerson" autoMapping="true">
<id column="id" property="id" />
<result column="first_name" property="name.firstName" />
<result column="last_name" property="name.lastName" />
</resultMap> |
List<X>
in mapper has only one element when usingresultMap
withassociation
.I have a mapper interface as follows:
and a mapper xml as follows:
Without
association
, it producesList<ComplexPerson>
having correct rows,but with
association
, it producesList<ComplexPerson>
having only one row.The following project is reproducing the problem:
https://github.com/izeye/samples-spring-boot-branches/tree/mybatis-lombok
The text was updated successfully, but these errors were encountered: