Skip to content

Commit 0cf19f0

Browse files
committed
Ignore collection like attributes for query by example.
Collection valued attributes no get ignored. Before RelationalExampleMapper tried to generate predicates for these, resulting in invalid SQL.
1 parent 9a0ed23 commit 0cf19f0

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

+5-20
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.junit.jupiter.params.ParameterizedTest;
4343
import org.junit.jupiter.params.provider.Arguments;
4444
import org.junit.jupiter.params.provider.MethodSource;
45-
4645
import org.springframework.beans.factory.annotation.Autowired;
4746
import org.springframework.beans.factory.config.PropertiesFactoryBean;
4847
import org.springframework.context.ApplicationListener;
@@ -52,16 +51,7 @@
5251
import org.springframework.core.io.ClassPathResource;
5352
import org.springframework.dao.IncorrectResultSizeDataAccessException;
5453
import org.springframework.data.annotation.Id;
55-
import org.springframework.data.domain.Example;
56-
import org.springframework.data.domain.ExampleMatcher;
57-
import org.springframework.data.domain.Limit;
58-
import org.springframework.data.domain.Page;
59-
import org.springframework.data.domain.PageRequest;
60-
import org.springframework.data.domain.Pageable;
61-
import org.springframework.data.domain.ScrollPosition;
62-
import org.springframework.data.domain.Slice;
63-
import org.springframework.data.domain.Sort;
64-
import org.springframework.data.domain.Window;
54+
import org.springframework.data.domain.*;
6555
import org.springframework.data.jdbc.core.mapping.AggregateReference;
6656
import org.springframework.data.jdbc.repository.query.Modifying;
6757
import org.springframework.data.jdbc.repository.query.Query;
@@ -924,19 +914,18 @@ void findAllByExamplePageable(Pageable pageRequest, int size, int totalPages, Li
924914
}
925915

926916
@Test
927-
void findByExampleWithCollection(){
917+
void findByExampleWithCollection() {
928918

929919
List<Root> roots = rootRepository.saveAll(List.of(createRoot("one"), createRoot("two")));
930920

931-
Example<Root> example = Example.of(new Root(null, "one", null, null));
921+
Example<Root> example = Example
922+
.of(new Root(null, "one", null, List.of(new Intermediate(null, "peter", null, null))));
932923

933-
Iterable<RootProjection> result = rootRepository.findAll(example);
924+
Iterable<Root> result = rootRepository.findAll(example);
934925

935926
assertThat(result).contains(roots.get(0));
936-
System.out.println(result);
937927
}
938928

939-
940929
public static Stream<Arguments> findAllByExamplePageableSource() {
941930
return Stream.of( //
942931
Arguments.of(PageRequest.of(0, 3), 3, 34, Arrays.asList("3", "4", "100")), //
@@ -1653,10 +1642,6 @@ public String toString() {
16531642
}
16541643
}
16551644

1656-
interface RootProjection {
1657-
String getName();
1658-
}
1659-
16601645
@Table("WITH_DELIMITED_COLUMN")
16611646
static class WithDelimitedColumn {
16621647
@Id Long id;

spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/RelationalExampleMapper.java

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntit
7878

7979
entity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) property -> {
8080

81+
if (property.isCollectionLike()) {
82+
return;
83+
}
84+
8185
if (matcherAccessor.isIgnoredPath(property.getName())) {
8286
return;
8387
}

0 commit comments

Comments
 (0)