About the Bug...

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of MyBatis.

  • [x] I have confirmed this bug reproduces without 3rd party extensions (e.g. mybatis-plus).

Database Version

MySQL 8

JDBC Driver Version

mysql 8

Issue Description

import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TestMapper {

    @Data
    class TestEntity {
        private Long id;
        private String name;

        public TestEntity(Long id, String name) {
            this.name = name;
            this.id = id;
        }
    }

    @Select("SELECT 'jojo' AS name, ${id} AS id")
    TestEntity getEntity(Long id);

}
Caused by: java.sql.SQLDataException: Cannot determine value type from string 'jojo'
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:115)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:98)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:90)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:64)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:74)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:96)
    at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1431)
    at com.mysql.cj.jdbc.result.ResultSetImpl.getLong(ResultSetImpl.java:856)
    at com.mysql.cj.jdbc.result.ResultSetImpl.getLong(ResultSetImpl.java:862)
    at com.alibaba.druid.filter.FilterChainImpl.resultSet_getLong(FilterChainImpl.java:1161)
    at com.alibaba.druid.filter.FilterAdapter.resultSet_getLong(FilterAdapter.java:1640)
    at com.alibaba.druid.filter.FilterChainImpl.resultSet_getLong(FilterChainImpl.java:1157)
    at com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl.getLong(ResultSetProxyImpl.java:493)
    at com.alibaba.druid.pool.DruidPooledResultSet.getLong(DruidPooledResultSet.java:289)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:68)
    at com.sun.proxy.$Proxy103.getLong(Unknown Source)
    at org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:35)
    at org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:26)
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:86)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyColumnOrderBasedConstructorAutomapping(DefaultResultSetHandler.java:783)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyConstructorAutomapping(DefaultResultSetHandler.java:770)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:721)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:685)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:655)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:407)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:362)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:333)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:306)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:202)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:66)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:80)
    at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:67)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:333)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:158)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:110)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:90)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:154)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:142)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425)
    ... 73 more

  • https://github.com/mybatis/mybatis-3/blob/mybatis-3.5.19/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java#L795
  • https://github.com/mybatis/mybatis-3/blob/mybatis-3.5.19/src/main/java/org/apache/ibatis/executor/resultset/ResultSetWrapper.java#L59

About your report...

  • [x] I did not use images 🖼️ for showing text information (code, error, etc.).

  • [x] I checked the Preview and my report looks awesome! 👍

Comment From: wuwen5

This configuration should work for your case

Setting Description Valid Values Default
argNameBasedConstructorAutoMapping When applying constructor auto-mapping, argument name is used to search the column to map instead of relying on the column order. (Since 3.5.10) true | false false

Comment From: harawata

Hello @niuheshui ,

Assuming @wuwen5 's suggestion helped you solve the problem, I will close this issue. If that is not the case, please explain and we will reopen.