Arcaniel
Arcaniel

Reputation: 127

Create query with not required parameter Spring Data Jpa

I have interface like this:

public List<Event> findByUseNameAndStartDateBefore(String name, Date startDate);

if I make call like this:

userService.findByUseNameAndStartDateBefore(name, date);

it's working fine, but if call is without some argument:

userService.findByUseNameAndStartDateBefore(name);

[Assertion failed] - this argument is required; it must not be null

Questin is: how can I make some parameters not required? (data in this case)

Upvotes: 1

Views: 1055

Answers (1)

dunni
dunni

Reputation: 44515

Create a method

public List<Event> findByUseName(String name);

A method named findByUseNameAndStartDateBefore without using the parameters one would assume according to the method name makes no sense and is against clean code rules (which also will affect the ability to understand the code for other developers).

Upvotes: 1

Related Questions