Closed
Description
Issue
While upgrading an application from SpringBoot2/MyBatisSpring2
to SpringBoot3/MyBatisSpring3
I noticed errors while running the tests:
Failed to find a constructor in 'com.example.demo.Foo' by arg names [id, name]. There might be more info in debug log.
Debugging org.apache.ibatis.mapping.ResultMap
showed that the argNames
were resolved correctly yet argTypesMatch()
returned false, which in turn lead to the error above.
Workaround
- use
class
instead ofrecord
- use
javaType
in theresultMap
- explicit downgrade (via
pom.xml
to3.5.9
)
MyBatis version
3.5.11
Database vendor and version
PostgreSQL 14.4
Test case or example project
https://github.com/tzie0062/issue-mybatis-record
Steps to reproduce
Using a resultMap with records
Expected result
Mapper works
Actual result
Mapper fails with
Caused by: org.apache.ibatis.builder.BuilderException: Error in result map 'com.example.demo.FooRepository.foo_map'. Failed to find a constructor in 'com.example.demo.Foo' by arg names [id, name]. There might be more info in debug log.
at org.apache.ibatis.mapping.ResultMap$Builder.build(ResultMap.java:130)
at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:208)
at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:289)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:254)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:246)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:119)
... 102 more