Could not parse literal [9223372036854775808] as integer

Description

The following query fails with "Could not parse literal [9223372036854775808] as integer"

“counter” is of type long.

Relevant stacktrace:
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not parse literal [9223372036854775808] as integer
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:725)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:113)
at dk.amc.xkernel.table.XkernelTableInternalHibernate.getRowCount(XkernelTableInternalHibernate.java:466)
... 30 more
Caused by: org.hibernate.HibernateException: Could not parse literal [9223372036854775808] as integer
at org.hibernate.hql.internal.ast.util.LiteralProcessor.determineIntegerRepresentation(LiteralProcessor.java:248)
at org.hibernate.hql.internal.ast.util.LiteralProcessor.processNumeric(LiteralProcessor.java:209)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processNumericLiteral(HqlSqlWalker.java:1223)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.literal(HqlSqlBaseWalker.java:5668)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.constant(HqlSqlBaseWalker.java:3173)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1353)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.arithmeticExpr(HqlSqlBaseWalker.java:3405)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1368)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4771)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4240)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2161)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2089)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:827)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:621)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:325)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:273)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716)
... 32 more
Caused by: java.lang.NumberFormatException: For input string: "9223372036854775808"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:596)
at java.lang.Long.valueOf(Long.java:803)
at org.hibernate.hql.internal.ast.util.LiteralProcessor.determineIntegerRepresentation(LiteralProcessor.java:245)
... 55 more

Environment

Hibernate 5.4.21.Final
H2 1.4.200
JVM 1.8.261
Win 10.

Activity

Show:
Nathan Xu
September 13, 2020, 4:44 PM

PR created at . will work on it later.

Nathan Xu
September 13, 2020, 9:38 PM
Edited

It seems the literal is beyond the - Long.MAX_VALUE and thus naturally the string literal cannot be parsed as Long, let alone Integer.

I changed the query to and (counter = -9223372036854775808L)but the same exception is thrown. However, the exception message is confusing for L suffix has been added and the entity field is of long type, so I guess this ticket still exposes some imperfection.

For the above reason, I changed the ticket scope to fix the misleading exception message from

to

PR updated accordingly. Thanks for the bug reporting.

Assignee

Nathan Xu

Reporter

Andrias Sundskarð

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure