Skip to content

Commit ecb8cf9

Browse files
committed
DATAJPA-858 - Fixed collection contains handling for nested path traversals.
Previously the first property was checked for being a collection to trigger collection contains handling. This is wrong for nested property traversals as they might end up in a String for which a like binding has to be applied then. We're now inspecting the leaf property for being a collection to trigger that special binding.
1 parent a18605f commit ecb8cf9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public Predicate build() {
215215
case CONTAINING:
216216
case NOT_CONTAINING:
217217

218-
if (property.isCollection()) {
218+
if (property.getLeafProperty().isCollection()) {
219219

220220
Expression<Collection<Object>> propertyExpression = traversePath(root, property);
221221
Expression<Object> parameterExpression = provider.next(part).getExpression();

src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,4 +591,9 @@ List<User> findUsersByFirstnameForSpELExpressionWithParameterIndexOnlyWithEntity
591591
* DATAJPA-829
592592
*/
593593
List<User> findByRolesNotContaining(Role role);
594+
595+
/**
596+
* @see DATAJPA-858
597+
*/
598+
List<User> findByRolesNameContaining(String name);
594599
}

0 commit comments

Comments
 (0)