springboot jpa自定义原生sql 接收SELECT count(*) 的返回long类型结果

Long total = null;
Object singleResult=null;
try {
   String sqlStr = "SELECT count(*) from order_product op, `order` o WHERE  op.PRODUCT_UUID =:PRODUCTUUID and o.ORDER_UUID = op.ORDER_UUID and ( (:STARTINGTIME between o.STARTING_TIME and o.ENDING_TIME ) or ( :ENDINGTIME between o.STARTING_TIME and o.ENDING_TIME ) ) and o.IS_DELETED=:isDeleted ";
    singleResult = em.createNativeQuery(sqlStr)
         .setParameter("STARTINGTIME", startingTime)
         .setParameter("ENDINGTIME", endingTime)
         .setParameter("PRODUCTUUID", productUUid)
         .setParameter("isDeleted", Boolean.FALSE)
         .getSingleResult();
      total=Long.parseLong(singleResult.toString());

} catch (NoResultException e) {
   logger.info("No record found");
}
return total == null ? 0 : total.intValue();
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页