JPA 如何用Specification方式写count

有如下SQL:

SELECT 
  c.*,
 (SELECT count(*) FROM studentInfo s WHERE s.classId = c.id) numberOfStudents 
FROM classInfo c

想用JPA的Specification方式查询,该如何实现?请多多指教。

@Query?

Specification 只能查固定格式的sql吧,使用JpaSpecificationExecutor的@Query可以写原生态sql