From aeb78bc7d68b28d892fe08e3253aaacd6d483a26 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 26 Jun 2023 18:17:06 +0200 Subject: [PATCH] Fix QueryLiteral assertion error in table based multi-table insert handling --- .../mutation/internal/temptable/TableBasedInsertHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java index 48b617c4ec..5b4eba867e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java @@ -255,7 +255,7 @@ public class TableBasedInsertHandler implements InsertHandler { final Optimizer optimizer = ( (OptimizableGenerator) generator ).getOptimizer(); if ( optimizer != null && optimizer.getIncrementSize() > 1 ) { final TemporaryTableColumn rowNumberColumn = entityTable.getColumns() - .get( entityTable.getColumns().size() - 1 ); + .get( entityTable.getColumns().size() - ( sessionUidColumn == null ? 1 : 2 ) ); rowNumberType = (BasicType) rowNumberColumn.getJdbcMapping(); final ColumnReference columnReference = new ColumnReference( (String) null, @@ -293,7 +293,8 @@ public class TableBasedInsertHandler implements InsertHandler { if ( rowNumberType != null ) { values.getExpressions().add( new QueryLiteral<>( - i + 1, + rowNumberType.getJavaTypeDescriptor() + .wrap( i + 1, sessionFactory.getWrapperOptions() ), rowNumberType ) );