Skip to content

Commit 2a422f3

Browse files
authored
Merge pull request #2841 from harawata/gh-2834-result-map-regression
gh-2834 result map regression
2 parents b83c0f2 + cfde857 commit 2a422f3

File tree

14 files changed

+216
-23
lines changed

14 files changed

+216
-23
lines changed

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private Class<?> resolveResultJavaType(Class<?> resultType, String property, Cla
437437
if (javaType == null && property != null) {
438438
try {
439439
MetaClass metaResultType = MetaClass.forClass(resultType, configuration.getReflectorFactory());
440-
javaType = metaResultType.getGetterType(property);
440+
javaType = metaResultType.getSetterType(property);
441441
} catch (Exception e) {
442442
// ignore, following null check statement will deal with the situation
443443
}

src/main/java/org/apache/ibatis/mapping/ResultMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public ResultMap build() {
129129
if (actualArgNames == null) {
130130
throw new BuilderException("Error in result map '" + resultMap.id + "'. Failed to find a constructor in '"
131131
+ resultMap.getType().getName() + "' with arg names " + constructorArgNames
132-
+ ". Note that 'javaType' is required when there is no readable property with the same name ('name' is optional, BTW). There might be more info in debug log.");
132+
+ ". Note that 'javaType' is required when there is no writable property with the same name ('name' is optional, BTW). There might be more info in debug log.");
133133
}
134134
resultMap.constructorResultMappings.sort((o1, o2) -> {
135135
int paramIdx1 = actualArgNames.indexOf(o1.getProperty());

src/site/es/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ public class User {
986986
</constructor>]]></source>
987987

988988
<p>
989-
<code>javaType</code> can be omitted if there is a property with the same name and type.
989+
<code>javaType</code> can be omitted if there is a writable property with the same name and type.
990990
</p>
991991

992992
<p>El resto de atributos son los mismos que los de los elementos id y result.</p>

src/site/ja/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ public class User {
11021102
</constructor>]]></source>
11031103

11041104
<p>
1105-
引数と同じ名前、同じ型を持つプロパティが存在する場合 <code>javaType</code> は省略可能です。
1105+
引数と同じ名前、同じ型を持つ書き込み可能なプロパティが存在する場合 <code>javaType</code> は省略可能です。
11061106
</p>
11071107

11081108
<p>

src/site/ko/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ public class User {
986986
</constructor>]]></source>
987987

988988
<p>
989-
같은 이름과 형태의 property 가 있는 경우는 <code>javaType</code> 를 생략 할 수 있다.
989+
같은 이름과 형태의 쓰기 가능한 property 가 있는 경우는 <code>javaType</code> 를 생략 할 수 있다.
990990
</p>
991991

992992
<p>나머지 속성과 규칙은 id와 result엘리먼트와 동일하다.</p>

src/site/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ public class User {
11901190
</constructor>]]></source>
11911191

11921192
<p>
1193-
<code>javaType</code> can be omitted if there is a property with the same name and type.
1193+
<code>javaType</code> can be omitted if there is a writable property with the same name and type.
11941194
</p>
11951195

11961196
<p>

src/site/zh/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ public class User {
11351135
</constructor>]]></source>
11361136

11371137
<p>
1138-
如果存在名称和类型相同的属性,那么可以省略 <code>javaType</code> 。
1138+
如果存在名称和类型相同的可写属性,那么可以省略 <code>javaType</code> 。
11391139
</p>
11401140

11411141
<p>

src/test/java/org/apache/ibatis/submitted/record_type/RecordTypeMapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ public interface RecordTypeMapper {
3232
@Select("select val, id, url from prop where id = #{id}")
3333
Property selectProperty(int id);
3434

35-
@Arg(name = "id", column = "id", id = true)
36-
@Arg(name = "value", column = "val")
37-
@Arg(name = "URL", column = "url")
38-
@Select("select val, id, url from prop where id = #{id}")
39-
Property selectPropertyNoJavaType(int id);
40-
4135
@Insert("insert into prop (id, val, url) values (#{id}, #{value}, #{URL})")
4236
int insertProperty(Property property);
4337

src/test/java/org/apache/ibatis/submitted/record_type/RecordTypeTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ void testSelectRecord() {
5252
}
5353
}
5454

55-
@Test
56-
void shouldResolveConstructorArgType() {
57-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
58-
RecordTypeMapper mapper = sqlSession.getMapper(RecordTypeMapper.class);
59-
Property prop = mapper.selectPropertyNoJavaType(1);
60-
assertEquals("Val1!", prop.value());
61-
assertEquals("https://www.google.com", prop.URL());
62-
}
63-
}
64-
6555
@Test
6656
void testSelectRecordAutomapping() {
6757
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2009-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.unmatched_prop_type;
17+
18+
import org.apache.ibatis.annotations.Arg;
19+
import org.apache.ibatis.annotations.Result;
20+
import org.apache.ibatis.annotations.Select;
21+
22+
public interface UnmatchedPropTypeMapper {
23+
24+
// javaType is required for 'id'
25+
@Arg(id = true, column = "id", name = "id", javaType = String.class)
26+
@Arg(column = "name", name = "name")
27+
@Result(column = "dob", property = "dob")
28+
@Select("select * from users where id = #{id}")
29+
User getUser(Integer id);
30+
31+
}

0 commit comments

Comments
 (0)