Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Spring Data JPA method to use findBy for multiple fields and also use Containing clause for all the fields

I have a class called Profile and its JPA repository ProfileRepo I'm trying to use findBy method to find names using first name or middle name or last name and also using containing clause.

public class Profile{
    private String firstName;
    private String middleName;
    private String lastName;

    //getters and setters
}

Am using the following query in the JPA repository but it is not accepting the method

List<Profile> findByLastNameContainingOrFirstNameContainingOrMiddleNameContainingAllIgnoreCase(String firstName,
        String lastName,String midName);

Kindly help out.

like image 861
user2632905 Avatar asked Jun 07 '17 11:06

user2632905


1 Answers

Try this:

List<Profile> findByFirstNameIgnoreCaseContainingOrLastNameIgnoreCaseContainingOrMidNameIgnoreCaseContaining(String firstName, String lastName, String midName);

or this:

@Query("select p from Profile p where upper(p.firstName) like concat('%', upper(?1), '%') or upper(p.lastName) like concat('%', upper(?2), '%') or upper(p.midName) like concat('%', upper(?3), '%')")
List<Profile> getByNames(String firstName, String lastName, String midName);
like image 176
Cepr0 Avatar answered Oct 19 '22 03:10

Cepr0