diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java index babb4bf1c8..e8270d7585 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java @@ -181,7 +181,7 @@ public class ParameterParser { } else if ( c == '?' ) { // could be either an ordinal or JPA-positional parameter - if ( indx < stringLength - 2 && Character.isDigit( sqlString.charAt( indx + 1 ) ) ) { + if ( indx < stringLength - 1 && Character.isDigit( sqlString.charAt( indx + 1 ) ) ) { // a peek ahead showed this as an JPA-positional parameter final int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 ); final int chopLocation = right < 0 ? sqlString.length() : right; diff --git a/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java b/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java index ef88a4c199..b231059731 100644 --- a/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java +++ b/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java @@ -124,5 +124,15 @@ public class ParameterParserTest { assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("pxyz")); assertEquals( 2, recognizer.getNamedParameterDescriptionMap().size() ); } + + @Test + public void testParseJPAPositionalParameter() { + ParamLocationRecognizer recognizer = new ParamLocationRecognizer( 0 ); + ParameterParser.parse("from Stock s where s.stockCode = ?1 and s.xyz = ?1", recognizer); + assertEquals( 1, recognizer.getOrdinalParameterDescriptionMap().size() ); + + ParameterParser.parse("from Stock s where s.stockCode = ?1 and s.xyz = ?2", recognizer); + assertEquals( 2, recognizer.getOrdinalParameterDescriptionMap().size() ); + } }