【发布时间】:2019-12-03 18:11:13
【问题描述】:
我的数据库表中有一个 unsigned 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()。
我看到的一种方法是编写自定义存储库并进行解析。
想问问大家有没有遇到过这个问题,如果有,你们是怎么解决的?
谢谢。
【问题讨论】:
-
是否可以将数字(姓名?)存储为文本?
标签: java spring jpa spring-data mysql-8.0