From bc094901e06265c78404861daa66a8c6a254d03c Mon Sep 17 00:00:00 2001 From: lsiu Date: Wed, 21 Dec 2016 00:04:28 +0800 Subject: [PATCH] Fix HHH-11352 - the Pattern at buildShallowIndexPattern where "wordBoundary==true" should wrap the pattern properly with '\b' (cherry picked from commit 56f7466d52b49456bbf0178f7666d320de4812e1) --- .../dialect/pagination/SQLServer2005LimitHandler.java | 7 ++++--- .../dialect/SQLServer2005DialectTestCase.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java index 63f074149fe3..50497011b1c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java @@ -356,14 +356,15 @@ private static int shallowIndexOfPattern(final StringBuilder sb, final Pattern p * based on the search pattern that is not enclosed in parenthesis. * * @param pattern String search pattern. - * @param wordBoundardy whether to apply a word boundary restriction. + * @param wordBoundary whether to apply a word boundary restriction. * @return Compiled {@link Pattern}. */ - private static Pattern buildShallowIndexPattern(String pattern, boolean wordBoundardy) { + private static Pattern buildShallowIndexPattern(String pattern, boolean wordBoundary) { return Pattern.compile( "(" + - ( wordBoundardy ? "\\b" : "" ) + + ( wordBoundary ? "\\b" : "" ) + pattern + + ( wordBoundary ? "\\b" : "" ) + ")(?![^\\(|\\[]*(\\)|\\]))", Pattern.CASE_INSENSITIVE ); diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java index 669fd18d63ca..c908fc1f0ae9 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java @@ -127,6 +127,16 @@ public void testGetLimitStringAliasGenerationWithAliasesNoAs() { ); } + @Test + @TestForIssue(jiraKey = "HHH-11352") + public void testPagingWithColumnNameStartingWithFrom() { + final String sql = "select column1 c1, from_column c2 from table1"; + assertEquals( "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + + "select column1 c1, from_column c2 from table1 ) inner_query ) " + + "SELECT c1, c2 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + dialect.getLimitHandler().processSql(sql, toRowSelection(3, 5))); + } + @Test @TestForIssue(jiraKey = "HHH-7019") public void testGetLimitStringWithSubselect() {