springspring-bootspring-data-jpaspring-repositories

How to distinct counting with Spring JPA Repository


How do I do a distinct counting with Spring Data JPA? I do not want to use the @Query annotation. The equivalent sql query would be:

SELECT COUNT(DISTINCT rack) FROM store WHERE id = 10001;

I tried by writing the following query, but it isn't working:

int countDistinctRackById();

Solution

  • This should work :

    Integer countDistinctRackById(Long id);