curious1
curious1

Reputation: 14717

How to write a query with conditions such as A And (B Or C) with Spring Data query methods?

Based on the Spring Data documentation, it is easy to do conditions such as A Or B. Example:

List<Person> findByLastnameOrFirstname(String lastname, String firstname);

I wouild like to know how to write a query with conditions A And (B Or C). Something like the following:

List<Person> findByEmailAddressAnd(LastnameOrFirstname)(String emailAddress, String lastname, String firstname);

Thanks and regards.

Upvotes: 0

Views: 291

Answers (1)

manish
manish

Reputation: 20135

You can use the @Query annotation.

@Query("SELECT p FROM Person p WHERE p.emailAddress=:emailAddress AND (p.lastName=:lastName OR p.firstName=:firstName)")
List<Person> findByEmailAddressAnd(LastnameOrFirstname)(String emailAddress, String lastname, String firstname);

Upvotes: 2

Related Questions