JPA 请问怎样实现 select CASE WHEN END from

小弟初学JPA,东拼西凑出来了代码

public Page<SN> select(String product_id,···) {
  Page<SN> result = null;

  Specification<SN> queryCondition = new Specification<SN>() {
       @Override
        public Predicate toPredicate(Root<SN> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
            List<Predicate> predicateList = new ArrayList<>();
            if(!product_id.equals("empty")){
            predicateList.add(criteriaBuilder.equal(root.get("productID"), product_id));
         }
                                ·····
            return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
     }
    result = sndao.findAll(queryCondition, PageRequest.of(pageNo - 1, pageSize, Sort.by(Sort.Direction.DESC,sort)));                
}

目前实现的都是
select id from S where···
请问各位大佬怎样实现

select id,CASE WHEN (EXISTS(select N.id from N where S.id=N.id))

THEN '0'

ELSE '1'

END N.id

from S

where···

分成两句sql来拿
或者自己写sql
jpa本身就是以实体类和数据库字段绑定实现功能的,你还想通过条件获取查询结果