Skip to content

Commit 2f5f269

Browse files
Thomas Darimontodrotbohm
Thomas Darimont
authored andcommitted
DATAJPA-712 - Fix binding of SpEL parameters with IN-clause.
We now ensure that all the SpEL parameters are correctly substituted when used together with an IN-clause. Previously we incorrectly used the initial query as the result again which then only substituted the very last parameter correctly. Original pull request: #148.
1 parent f092c4e commit 2f5f269

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/main/java/org/springframework/data/jpa/repository/query/StringQuery.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -255,7 +255,6 @@ private final String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQu
255255
checkAndRegister(new InParameterBinding(parameterName, expression), bindings);
256256
}
257257

258-
result = query;
259258
break;
260259

261260
case AS_IS: // fall-through we don't need a special parameter binding for the given parameter.

src/test/java/org/springframework/data/jpa/repository/query/StringQueryUnitTests.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -312,7 +312,31 @@ public void detectsInBindingWithSpecialCharactersAndWordCharactersMixedInParenth
312312
public void rejectsDifferentBindingsForRepeatedParameter2() {
313313
new StringQuery("select u from User u where u.firstname like ?1 and u.lastname like %?1");
314314
}
315+
316+
/**
317+
* @see @DATAJPA-712
318+
*/
319+
@Test
320+
public void shouldReplaceAllNamedExpressionParametersWithInClause() {
321+
322+
StringQuery query = new StringQuery("select a from A a where a.b in :#{#bs} and a.c in :#{#cs}");
323+
String queryString = query.getQueryString();
324+
325+
assertThat(queryString, is("select a from A a where a.b in :__$synthetic$__1 and a.c in :__$synthetic$__2"));
326+
}
315327

328+
/**
329+
* @see @DATAJPA-712
330+
*/
331+
@Test
332+
public void shouldReplaceAllPositionExpressionParametersWithInClause() {
333+
334+
StringQuery query = new StringQuery("select a from A a where a.b in ?#{#bs} and a.c in ?#{#cs}");
335+
String queryString = query.getQueryString();
336+
337+
assertThat(queryString, is("select a from A a where a.b in ?1 and a.c in ?2"));
338+
}
339+
316340
private void assertPositionalBinding(Class<? extends ParameterBinding> bindingType, Integer position,
317341
ParameterBinding expectedBinding) {
318342

0 commit comments

Comments
 (0)