Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 联合<;整数>;ClassCastException,试图将其转换为Long_Java_Jpa_Criteria - Fatal编程技术网

Java 联合<;整数>;ClassCastException,试图将其转换为Long

Java 联合<;整数>;ClassCastException,试图将其转换为Long,java,jpa,criteria,Java,Jpa,Criteria,当我进行求和且没有行时,我尝试在查询中使用Coalesce返回0而不是NULL 这是我的密码: ... Root<ArticleBean> rootArticle = cq.from(ArticleBean.class); Coalesce<Integer> coalesce = cb.coalesce(); coalesce.value(cb.sum(rootArticle.get("quantity"))); coalesce.value(0); cq.select(

当我进行求和且没有行时,我尝试在查询中使用Coalesce返回0而不是NULL

这是我的密码:

...
Root<ArticleBean> rootArticle = cq.from(ArticleBean.class);
Coalesce<Integer> coalesce = cb.coalesce();
coalesce.value(cb.sum(rootArticle.get("quantity")));
coalesce.value(0);
cq.select(coalesce);

Query query = entityManager.createQuery(cq);

return (Integer) query.getSingleResult();
为什么要把结果拖得太久

特别是当我使用合并时,方法sum()返回一个表达式

我知道我可以做这样的事情:

((Long) query.getSingleResult()).intValue()
但我有点好奇,我想知道它为什么要投长

((Long) query.getSingleResult()).intValue()