项目用JPA做查询,前端调用到这个新增查询报错
提示:日常BUG
问题:新增一个查询,是查询数据库视图,前端页面调用时报错,提示”java.sql.SQLException: 数字溢出“
–
问题原因分析
问题:后台提示sql查询报错`
描述:查询用到的是视图,网上查找了关于” 数字溢出“的问题,介绍的都是Entity实体类与数据库字段长度不匹配,项目用的JPA是支持视图查询,查找自己实体与数据库字段类型都是匹配的。
确认问题:问题出在数据库中的数据,实体类定义主键是logn,最大长度只,支持19位到(9223372036854775806),如果数据库是20位或是以9224开头的19位数据都会报同样的错。
解决:可以限制数据库字段,最好是限制在18位,19位到9224这个数就超了,还会报错。
2022-08-25 14:34:27.984 |-WARN [http-nio-8888-exec-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper [137] -| SQL Error: 17026, SQLState: 99999
2022-08-25 14:34:27.986 |-ERROR [http-nio-8888-exec-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper [142] -| 数字溢出
--
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.loader.Loader.doList(Loader.java:2692)
at org.hibernate.loader.Loader.doList(Loader.java:2672)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
at org.hibernate.loader.Loader.list(Loader.java:2501)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
at org.hibernate.query.Query.getResultList(Query.java:132)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74)
---
Caused by: java.sql.SQLException: 数字溢出
---[27] -| 前端请求异常:org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query
Caused by: java.sql.SQLException: 数字溢出
at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4381)
at oracle.jdbc.driver.NumberCommonAccessor.getLong(NumberCommonAccessor.java:668)
at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:985)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:444)
at com.zaxxer.hikari.pool.HikariProxyResultSet.getLong(HikariProxyResultSet.java)
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:793)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:718)
at org.hibernate.loader.Loader.processResultSet(Loader.java:990)
at org.hibernate.loader.Loader.doQuery(Loader.java:948)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
at org.hibernate.loader.Loader.doList(Loader.java:2689)
... 114 more