Damien GIBOU ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWM4OWE1YjI3... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16678?atlOrigin=eyJpIjoiMWM4OW... ) HHH-16678 ( https://hibernate.atlassian.net/browse/HHH-16678?atlOrigin=eyJpIjoiMWM4OW... ) AssertionError in QueryLiteral.<init> when using "update versioned Entity ..." if @Version is a long ( https://hibernate.atlassian.net/browse/HHH-16678?atlOrigin=eyJpIjoiMWM4OW... )
Issue Type: Bug Affects Versions: 6.2.2 Assignee: Unassigned Components: hibernate-core Created: 23/May/2023 07:27 AM Environment: Found using Spring Boot 3.1.0/Hibernate 6.2.2 Priority: Major Reporter: Damien GIBOU ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... )
If an entity has a long (or Long) @Version field
@Version
private long optimisticVersion;
A query like the following:
update versioned Entity set x=true where x=false
will lead to the following Assertion:
ava.lang.AssertionError: null
at org.hibernate.sql.ast.tree.expression.QueryLiteral.<init>(QueryLiteral.java:36)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.addVersionedAssignment(BaseSqmToSqlAstConverter.java:910)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitUpdateStatement(BaseSqmToSqlAstConverter.java:829)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitUpdateStatement(BaseSqmToSqlAstConverter.java:429)
at org.hibernate.query.sqm.tree.update.SqmUpdateStatement.accept(SqmUpdateStatement.java:168)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.translate(BaseSqmToSqlAstConverter.java:767)
at org.hibernate.query.sqm.internal.SimpleUpdateQueryPlan.createUpdateTranslator(SimpleUpdateQueryPlan.java:116)
at org.hibernate.query.sqm.internal.SimpleUpdateQueryPlan.executeUpdate(SimpleUpdateQueryPlan.java:61)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doExecuteUpdate(QuerySqmImpl.java:735)
at org.hibernate.query.sqm.internal.QuerySqmImpl.executeUpdate(QuerySqmImpl.java:705)
Changing the type of the optimisticVersion field to int/Integer allows to workaround the issue.
I have tracked down the problem to the following code in BaseSqmToSqlAstConverter.addVersionedAssignment(...) :
value = new BinaryArithmeticExpression(
versionColumn,
ADD,
new QueryLiteral<>( 1, versionType ),
versionType
);
1 is an Integer whereas versionType.getJdbcMapping() is a LongJavaType, explaining why the assertions fails in the QueryLiteral constructor.
The assertion should probably be relaxed to take into account that an int can be promoted to a long.
Or alternatively something like in the caller :
versionType.getJavaTypeClass() == Long.class ? new QueryLiteral<>( 1L, versionType ) : new QueryLiteral<>( 1, versionType )
The same issue may happen with other primitive types supporting promotion.
( https://hibernate.atlassian.net/browse/HHH-16678#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16678#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:bbd69a1 )