Skip to content
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

Circularly referenced resultMap is filled with ancestor object even when columnPrefix is specified. #215

Closed
ooknight opened this issue Jun 6, 2014 · 5 comments
Assignees
Labels
Milestone

Comments

@ooknight
Copy link

ooknight commented Jun 6, 2014

mapper :

<resultMap id="user" type="User">
  <id property="id" column="id"/>
  <result property="name" column="name"/>
  <association property="superior" resultMap="user" columnPrefix="superior_" />
</resultMap>

<select id="find" parameterType="long" resultMap="user">
  select 1 as id, 'a' as name, 2 as superior_id , 'b' as superior_name from dual
</select>

java :

User user = dao.find(1L);
System.out.println("user.id : " + user.getId());
System.out.println("user.name : " + user.getName());
System.out.println("user.superior.id : " + user.getSuperior().getId());
System.out.println("user.superior.name : " + user.getSuperior().getName());

result :

[DEBUG] ==>  Preparing: select 1 as id, 'a' as name, 2 as superior_id , 'b' as superior_name from dual  [org.ufox.demo.dao.UserDao.find] 
[DEBUG] ==> Parameters:  [org.ufox.demo.dao.UserDao.find] 
[DEBUG] <==      Total: 1 [org.ufox.demo.dao.UserDao.find] 
user.id : 1
user.name : a
user.superior.id : 1
user.superior.name : a
@ooknight
Copy link
Author

ooknight commented Jun 6, 2014

3.2.3 is ok, 3.2.4 - 3.2.7 has this bug
if (ancestorColumnPrefix.containsKey(nestedResultMapId)) {
rowKey = createRowKey(nestedResultMap, rsw, ancestorColumnPrefix.get(nestedResultMapId));
ancestorObject = ancestorObjects.get(rowKey);
}
ancestorColumnPrefix.get(nestedResultMapId)) return null, rowKey is same

@emacarron
Copy link
Member

Hi @ooknight Thank you very much for the bug report.

Can you please submit a test?

@harawata
Copy link
Member

harawata commented Jun 6, 2014

Your resultMap contains circular reference.
Try this:

<resultMap id="user" type="User">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
</resultMap>

<resultMap id="userAndSuperior" type="User" extends="user">
    <association property="superior" resultMap="user" columnPrefix="superior_" />
</resultMap>

<select id="find" parameterType="long" resultMap="userAndSuperior">
    select 1 as id, 'a' as name, 2 as superior_id , 'b' as superior_name from dual
</select>

@loicortola
Copy link

+1 for the issue:
Shouldn't mybatis be able to resolve such dependencies? It is not really a circular difference, because the columnprefix should allow nested objects to be populated within the same mapper.

I am having the same issue with a similar design in 3.2.7. I will use harawata's pattern as a workaround, but I think we are losing some of the flexibility of mappers (and columnPrefix becomes obsolete). --> Might be interesting to solve this

@harawata
Copy link
Member

harawata commented May 12, 2016

A test case contributed by another user in the forum seems to be the test case for this issue.
Reopening with the test case : 93757d2.

@harawata harawata reopened this May 12, 2016
@harawata harawata changed the title resultMap bug Circularly referenced resultMap is filled with ancestor object even when columnPrefix is specified. May 17, 2016
@harawata harawata added the bug label May 17, 2016
@harawata harawata added this to the 3.4.1 milestone May 17, 2016
@harawata harawata self-assigned this May 17, 2016
harawata added a commit that referenced this issue May 23, 2016
…orResult does not have columnPrefix attribute, so MyBatis tries to lookup ancestor stored under the same resultMapID.
emacarron added a commit that referenced this issue May 26, 2016
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
… referenced resultMap will be filled with ancestor only when the columnPrefix attribute is not specified for the nested result mapping. 2) When columnPrefix is specified for a nested result mapping and there is no column with that prefix in the result set, skip filling the nested result mapping to prevent stack overflow.
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
…he authorResult does not have columnPrefix attribute, so MyBatis tries to lookup ancestor stored under the same resultMapID.
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants