Mybatis查询bigInteger错误

mybatis查询bigInteger错误这里是堆栈信息,如果你缩短长度没问题,例如982544369348876697

原因:java.sql.SQLException:java.lang.NumberFormatException:9825443693488766976

; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1105]; java.lang.NumberFormatException: 9825443693488766976; nested exception is java.sql.SQLException: java.lang.NumberFormatException: 9825443693488766976
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) ~[spring-jdbc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[mybatis-spring-1.3.2.jar:1.3.2]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) ~[mybatis-spring-1.3.2.jar:1.3.2]
    at com.sun.proxy.$Proxy35.selectList(Unknown Source) ~[?:?]
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) ~[mybatis-spring-1.3.2.jar:1.3.2]
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128) ~[mybatis-3.4.0.jar:3.4.0]
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68) ~[mybatis-3.4.0.jar:3.4.0]
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.4.0.jar:3.4.0]
    at com.sun.proxy.$Proxy69.selectJobTransactionEvent(Unknown Source) ~[?:?]

回答(1)

3 years ago

问题是您正在尝试从数据库中检索一个大数字,并且它不能存储在Java Long (您在VO中指定)中 .

你不是't say what'的列数据类型,但我的猜测是它像 UNSIGNED BIGINT . 这些列支持的数字大于 9223372036854775807 ,这是Java Long的最大值 .

解?在Java Value Object中使用 java.math.BigInteger 而不是Long . 我尝试过它并且像魅力一样工作 .