Could not parse literal [9223372036854775808] as integer

Description

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

select count(*) from Table1 where instanceId = '5d060a98-aec3-4fe7-a6e0-e3a55c10623a' and (counter = -9223372036854775808)

“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

Activity

Show:

Nathan XuSeptember 13, 2020 at 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

"Could not parse literal [9223372036854775808] as integer"

to

"Could not parse literal [9223372036854775808] as java.lang.Long"

PR updated accordingly. Thanks for the bug reporting.

Nathan XuSeptember 13, 2020 at 4:44 PM

PR created at https://github.com/hibernate/hibernate-orm/pull/3549 . will work on it later.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created September 9, 2020 at 10:11 AM
Updated September 30, 2020 at 5:35 PM
Resolved September 14, 2020 at 7:43 AM

Flag notifications