[英]Spring data JPA casting unsigned BITINT to Long instead of BigInteger
I have a unsigned bigint(20) column in my database table. 我的数据库表中有一个未签名的bigint(20)列。
mysql driver version
8.0.14
My JPA entity looks like: 我的JPA实体看起来像:
BigInteger columnName;
Problem is when I try to get data using the following select query: 问题是当我尝试使用以下选择查询获取数据时:
select * from table where columnName in (large number [unsigned bigint])
I get the following error: 我收到以下错误:
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)
So I saw the code for ResultSetImpl found this 所以我看到ResultSetImpl的代码找到了这个
case BIGINT:
return Long.valueOf(getLong(columnIndex));
case BIGINT_UNSIGNED:
return getBigInteger(columnIndex);
but it was still calling getLong() even though data type in table was unsigned bigint(20). 但是,即使表中的数据类型为unsigned bigint(20),它仍在调用getLong()。
One way around which I see is to write a custom repository and do the parsing. 我看到的一种方法是编写自定义存储库并进行解析。
Wanted to ask have any of you faced this issue, If yes how have you gone about it ? 想问问你们中的任何一个人面临过这个问题吗?
Thanks. 谢谢。
You have not presented your DDL (Data Definition Language) for your datatype, so I cannot be sure what your datatype in the database actually is actually. 您尚未提供数据类型的DDL(数据定义语言),因此我无法确定数据库中实际的数据类型是什么。 What you can do is cast it within your query using
cast()
function. 您可以执行的操作是使用
cast()
函数在查询中对其进行cast()
。 So, your query would look like this: 因此,您的查询将如下所示:
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.