HHH-12175: ParameterParser doesn't handle JPA positional parameters correctly

This commit is contained in:
Jonathan Bregler 2017-12-15 15:32:30 +01:00 committed by Steve Ebersole
parent 90cabb43ad
commit 8eaf649aa3
2 changed files with 11 additions and 1 deletions

View File

@ -181,7 +181,7 @@ public class ParameterParser {
} }
else if ( c == '?' ) { else if ( c == '?' ) {
// could be either an ordinal or JPA-positional parameter // 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 // a peek ahead showed this as an JPA-positional parameter
final int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 ); final int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 );
final int chopLocation = right < 0 ? sqlString.length() : right; final int chopLocation = right < 0 ? sqlString.length() : right;

View File

@ -124,5 +124,15 @@ public class ParameterParserTest {
assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("pxyz")); assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("pxyz"));
assertEquals( 2, recognizer.getNamedParameterDescriptionMap().size() ); 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() );
}
} }