Skip to content

Commit 89cf386

Browse files
committed
Ignore collection like attributes for query by example.
Collection valued attributes now get ignored. Before RelationalExampleMapper tried to generate predicates for these, resulting in invalid SQL. Original pull request #1969
1 parent 02e588e commit 89cf386

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

+15-12
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;
@@ -923,6 +913,19 @@ void findAllByExamplePageable(Pageable pageRequest, int size, int totalPages, Li
923913
}
924914
}
925915

916+
@Test
917+
void findByExampleWithCollection() {
918+
919+
List<Root> roots = rootRepository.saveAll(List.of(createRoot("one"), createRoot("two")));
920+
921+
Example<Root> example = Example
922+
.of(new Root(null, "one", null, List.of(new Intermediate(null, "peter", null, null))));
923+
924+
Iterable<Root> result = rootRepository.findAll(example);
925+
926+
assertThat(result).contains(roots.get(0));
927+
}
928+
926929
public static Stream<Arguments> findAllByExamplePageableSource() {
927930
return Stream.of( //
928931
Arguments.of(PageRequest.of(0, 3), 3, 34, Arrays.asList("3", "4", "100")), //
@@ -1509,7 +1512,7 @@ interface DummyEntityRepository extends CrudRepository<DummyEntity, Long>, Query
15091512
List<DummyEntity> findByBytes(byte[] bytes);
15101513
}
15111514

1512-
interface RootRepository extends ListCrudRepository<Root, Long> {
1515+
interface RootRepository extends ListCrudRepository<Root, Long>, QueryByExampleExecutor<Root> {
15131516
List<Root> findAllByOrderByIdAsc();
15141517
}
15151518

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)