I have an Entity Class like this:
@Entity
@Table(name = "CUSTOMER")
class Customer{
@Id
@Column(name = "Id")
Long id;
@Column(name = "EMAIL_ID")
String emailId;
@Column(name = "MOBILE")
String mobile;
}
How to write findBy method for the below query using crudrepository spring data jpa?
select * from customer where (email, mobile) IN (("a@b.c","8971"), ("e@f.g", "8888"))
I'm expecting something like
List<Customer> findByEmailMobileIn(List<Tuple> tuples);
I want to get the list of customers from given pairs
I think this can be done with
org.springframework.data.jpa.domain.Specification
. You can pass a list of your tuples and proceed them this way (don't care that Tuple is not an entity, but you need to define this class):Your repo is supposed to extend interface
JpaSpecificationExecutor<Customer>
.Then construct a specification with a list of tuples and pass it to the method
customerRepo.findAll(Specification<Customer>)
- it returns a list of customers.It is maybe cleaner using a projection :
The Contact Entity :
After specifying the entities, the repo :
And the repo call :
Not tested code.