Spring Data JPA Query - count with in clause

Viewed 13210

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!

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);
Related