java.sql.SQLException: Fail to convert to internal representation

message: "Error attempting to get column 'PARAM_NAME' from result set. 
Cause: java.sql.SQLException: Fail to convert to internal representation↵; 
uncategorized SQLException; SQL state [99999]; error code [17059];
 Fail to convert to internal representation; 
nested exception is java.sql.SQLException: 
Fail to convert to internal representation"

 

Java

package com.app.dto;



public class DiversityCustomAttrDTO {

    private Long numberValue;

    private String paramName;



    public DiversityCustomAttrDTO(Long numberValue, String paramName) {

       this.numberValue = numberValue;

       this.paramName = paramName;

    }



// getters setters

}

 

MyBatis



    

    

 

怎么看都没问题,删掉代码一行行加回来,原来是IDEA自动生成构造函数的参数顺序和resultset里result顺序不匹配时就会报错。

删掉构造函数 - 工作

加上默认无参的构造函数 - 工作

调整参数顺序和resultset里一样 - 工作

 

那么基本可以推测,mybatis ibatis 源码里当遇到有构造函数的时候,而且有没有无参的构造函数,参数顺序就必须和resultset里是一致的。

推测底层是通过反射来实例化的,看下反射类中的Constructor,只能拿到

private Class[] parameterTypes;

所以当我们的构造函数第一个是long,而result里是varchar,也就是String时,就报错了。

 

你可能感兴趣的:(java,java)