From c5bc1f2884841977408e10311645e78b37d2c2d5 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 29 Sep 2021 09:16:45 -0700 Subject: [PATCH] Revert "HHH-14649 Oracle limit handler create wrong sql query when multiple spaces are present in the query" This reverts commit 31ac883f36edef573f6fa812b88136b32ababa40. --- .../hibernate/dialect/pagination/Oracle12LimitHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/Oracle12LimitHandler.java b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/Oracle12LimitHandler.java index c4d7f23f15..3067a01a81 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/Oracle12LimitHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/Oracle12LimitHandler.java @@ -52,7 +52,6 @@ public class Oracle12LimitHandler extends AbstractLimitHandler { if ( !hasMaxRows ) { return sql; } - sql = sql.trim(); final LockOptions lockOptions = queryParameters.getLockOptions(); if ( lockOptions != null ) { @@ -84,6 +83,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler { bindLimitParametersInReverseOrder = false; useMaxForLimit = false; + sql = normalizeStatement( sql ); final int offsetFetchLength; final String offsetFetchString; if ( hasFirstRow ) { @@ -100,6 +100,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler { private String processSql(String sql, int forUpdateIndex, boolean hasFirstRow) { bindLimitParametersInReverseOrder = true; useMaxForLimit = true; + sql = normalizeStatement( sql ); String forUpdateClause = null; boolean isForUpdate = false; @@ -141,6 +142,10 @@ public class Oracle12LimitHandler extends AbstractLimitHandler { return pagingSelect.toString(); } + private String normalizeStatement(String sql) { + return sql.trim().replaceAll( "\\s+", " " ); + } + private int getForUpdateIndex(String sql) { final int forUpdateLastIndex = sql.toLowerCase( Locale.ROOT ).lastIndexOf( "for update" ); // We need to recognize cases like : select a from t where b = 'for update';