繁体   English   中英

Spring数据JPA将无符号BITINT强制转换为Long而不是BigInteger

[英]Spring data JPA casting unsigned BITINT to Long instead of BigInteger

我的数据库表中有一个未签名的bigint(20)列。

mysql driver version
8.0.14

我的JPA实体看起来像:

BigInteger columnName;

问题是当我尝试使用以下选择查询获取数据时:

select * from table where columnName in (large number [unsigned bigint])

我收到以下错误:

java.sql.SQLDataException: Value '13,224,435,352,132,323,241' is outside of valid range for type java.lang.Long
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:114)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:92)
        at com.mysql.cj.jdbc.result.ResultSetImpl.getLong(ResultSetImpl.java:923)
        at com.mysql.cj.jdbc.result.ResultSetImpl.getLong(ResultSetImpl.java:928)

所以我看到ResultSetImpl的代码找到了这个

case BIGINT:
    return Long.valueOf(getLong(columnIndex));

case BIGINT_UNSIGNED:
    return getBigInteger(columnIndex);

但是,即使表中的数据类型为unsigned bigint(20),它仍在调用getLong()。

我看到的一种方法是编写自定义存储库并进行解析。

想问问你们中的任何一个人面临过这个问题吗?

谢谢。

您尚未提供数据类型的DDL(数据定义语言),因此我无法确定数据库中实际的数据类型是什么。 您可以执行的操作是使用cast()函数在查询中对其进行cast() 因此,您的查询将如下所示:

select column, column, cast(bigint_unsigned_column as unsigned bigint), column
from table where columnName in (large number [unsigned bigint])

更新:我通过将jdbcTemplate与rowMapper一起使用来将有问题的列转换为Biginteger / BigDecimal来解决此问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM