Skip to content

Commit

Permalink
Ignore collection like attributes for query by example.
Browse files Browse the repository at this point in the history
Collection valued attributes no get ignored.
Before RelationalExampleMapper tried to generate predicates for these, resulting in invalid SQL.

Original pull request #1969
  • Loading branch information
schauder committed Jan 6, 2025
1 parent 02e588e commit 0772cdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ApplicationListener;
Expand All @@ -52,16 +51,7 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Limit;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Window;
import org.springframework.data.domain.*;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
Expand Down Expand Up @@ -923,6 +913,19 @@ void findAllByExamplePageable(Pageable pageRequest, int size, int totalPages, Li
}
}

@Test
void findByExampleWithCollection() {

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

Example<Root> example = Example
.of(new Root(null, "one", null, List.of(new Intermediate(null, "peter", null, null))));

Iterable<Root> result = rootRepository.findAll(example);

assertThat(result).contains(roots.get(0));
}

public static Stream<Arguments> findAllByExamplePageableSource() {
return Stream.of( //
Arguments.of(PageRequest.of(0, 3), 3, 34, Arrays.asList("3", "4", "100")), //
Expand Down Expand Up @@ -1509,7 +1512,7 @@ interface DummyEntityRepository extends CrudRepository<DummyEntity, Long>, Query
List<DummyEntity> findByBytes(byte[] bytes);
}

interface RootRepository extends ListCrudRepository<Root, Long> {
interface RootRepository extends ListCrudRepository<Root, Long>, QueryByExampleExecutor<Root> {
List<Root> findAllByOrderByIdAsc();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntit

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

if (property.isCollectionLike()) {
return;
}

if (matcherAccessor.isIgnoredPath(property.getName())) {
return;
}
Expand Down

0 comments on commit 0772cdd

Please sign in to comment.