Skip to content

Commit dbb27ef

Browse files
committed
Reverting mybatis#2804
Result mapping java type resolution fails when the target property has different types for writing and reading. mybatis#2834
1 parent b83c0f2 commit dbb27ef

File tree

4 files changed

+3
-19
lines changed

4 files changed

+3
-19
lines changed

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

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public ResultMap build() {
128128
final List<String> actualArgNames = argNamesOfMatchingConstructor(constructorArgNames);
129129
if (actualArgNames == null) {
130130
throw new BuilderException("Error in result map '" + resultMap.id + "'. Failed to find a constructor in '"
131-
+ 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.");
131+
+ resultMap.getType().getName() + "' by arg names " + constructorArgNames
132+
+ ". There might be more info in debug log.");
133133
}
134134
resultMap.constructorResultMappings.sort((o1, o2) -> {
135135
int paramIdx1 = actualArgNames.indexOf(o1.getProperty());

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

-6
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

-10
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()) {

0 commit comments

Comments
 (0)