2

Using Spring Data REST and Spring Data JPA, I need to arbitrarily filter for entities by none/some/all of an entity's attributes at the same time.

For example, with a PersonRepository, search for a Person with firstName=something and/or lastLame=something and/or birthday before someDate and/or birthday after someOtherDate... etc etc. Spring Data Rest allows you to search for multiple attributes, but only for a fixed combination of attributes, and not for the same attribute repeated.

I thought I would implement this using a custom jpa repository implementation with an implementation using Specifications and a signature like

public Page<Scanner> findByAny(Parameters queryParams, Pageable pageData) {

But it looks like you can't do this - it's specifically disallowed. (See SO question: Custom jpa repository method published by spring-data-rest)

Reading some more, this SO question and answer is close, but you can't specify an attribute more than once, and as it's MVC I'm not sure it will show up in an entity's search metadata and search urls constructed by SDR.

Is there another good way to specify arbitrary elements in the search? (I'm using spring-data-rest:2.3.0.RELEASE)

Community
  • 1
  • 1
Jason
  • 7,356
  • 4
  • 41
  • 48

0 Answers0