Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA Query - count with in clause

I am trying to implement the following query with spring data JPA with method name resolving.

select count(*) from example ex where ex.id = id and ex.status in (1, 2);

I know there's a method in crud repo for count which will go like - countByIdAndStatus(params) but I wasn't sure how can I incorporate "in" clause with this method.

Thank you!

like image 275
Kalyani Shirwalkar Avatar asked Aug 28 '18 12:08

Kalyani Shirwalkar


1 Answers

This is how you can do it:

long countByIdAndStatusIn(Integer id, List<Type> params);

With @Query:

@Query("select count(*) from Example ex where ex.id = ?1 and ex.status in (?2)")
long countByIdAndStatus(Integer id, List<Type> params);
like image 82
Branislav Lazic Avatar answered Nov 15 '22 09:11

Branislav Lazic