0

Hi I am working with spring-data and I am using repositories, then i just figured out that one method is not working properly for the AND-OR distribution. Here is me method.

long countByNameAndStartDateBetweenOrFinishDateBetween(String name, Date startDateFrom, Date startDateTo, Date endDateFrom, Date endDateTo);

And i would like to recover the number of users with a particular name and wheen the startDate is in between a range or the finishDate is in between a range.

But he is combining Name&startDate - Or finishDate so return the number of records with the finishDate in between.

Is possible to do it with spring data? Should i use @Query annotation and write my query there?

Thanks!

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
cralfaro
  • 5,822
  • 3
  • 20
  • 30
  • *Should i use `@Query`*: yes: for all but straight simple queries where the method name is readable, you should use `@Query`.If the method doesn't have the name you would have chosen by yourself to express what the method does, then use `@Query`. – JB Nizet Apr 02 '16 at 11:32
  • @JBNizet finally i changed to "@Query" and works fine. But i was wondering if spring-data had something for this situations – cralfaro Apr 02 '16 at 12:09

1 Answers1

1

Spring Repositories naming convention gives you only that much. If the method naming convention doesn't work for you, use the @Query annotation

Marco Tedone
  • 592
  • 4
  • 13
  • is not really a response, i already comment in my question the option to use Query anntotation, but i was wondering how spring data could handle AND-OR combination – cralfaro Apr 04 '16 at 08:26