Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/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.lang.ClassCastException:org.hibernate.Criteria.PropertyProjection错误_Hibernate_Hql_Criteria - Fatal编程技术网

获取java.lang.ClassCastException:org.hibernate.Criteria.PropertyProjection错误

获取java.lang.ClassCastException:org.hibernate.Criteria.PropertyProjection错误,hibernate,hql,criteria,Hibernate,Hql,Criteria,我想使用Hibernate条件实现以下SQL查询: select abc_id, count(*) from boa_rep_deed where sync_system = ? And hook_id = ? group by abc_id order by abc_id 我试过的是这个 List<teedObject> hytlow = null; Criteria criteria = session.createCriteria(teedObject.cla

我想使用Hibernate条件实现以下SQL查询:

select abc_id, count(*) from boa_rep_deed where sync_system = ? And hook_id = ? group by abc_id order by abc_id
我试过的是这个

List<teedObject> hytlow = null;
        Criteria criteria = session.createCriteria(teedObject.class);
        criteria.add(Restrictions.ne("abcID ", abcID));
        criteria.add(Restrictions.eq("syncSystem", syncSystem));
        criteria.add(Restrictions.eq("hookId", hookId));

        hytlow = criteria.list();
现在,我希望我的条件只获取某些列,以便使对象更轻,因此我必须使用条件中的投影,请您建议如何在我的情况下使用投影,以便仅获取某些列,我已经尝试了此

Criteria cr = session.createCriteria(teedObject.class);
cr.add(Restrictions.eq("syncSystem", syncSystem));
cr.add(Restrictions.eq("hookId", hookId));
cr.addOrder(Order.asc("abcID"));
cr.add(Projections.groupProperty("abcID")));
cr.setProjection(Projections.rowCount());
hytlow = cr.list();
但它抛出了异常作为。。
java.lang.ClassCastException:org.hibernate.Criteria.PropertyProjection
。。请问我是否以正确的方式实施了这些预测

        List result = session.createCriteria(teedObject.class)       
                .add(Restrictions.eq("syncSystem", syncSystem))
                .add(Restrictions.eq("hookId", hookId))
                .setProjection(Projections.projectionList()
                        .add(Projections.groupProperty("abcID"))
                        .add(Projections.count("abcID"))           
                ).list();

请参见

谢谢,但我将如何在我的案例中实施此功能,请解释。我没有理解,我尝试过此功能。。Criteria cr=session.createCriteria(teedObject.class);cr.add(Restrictions.eq(“syncSystem”,syncSystem));cr.add(Restrictions.eq(“hookId”,hookId));cr.addOrder(Order.asc(“abcID”));cr.add(Projections.groupProperty(“abcID”));cr.setProjection(Projections.rowCount());hytlow=cr.list();但是在执行上述操作后,我收到了一个错误,请建议将“setProjection(Projections.rowCount());”替换为“setProjection(Projections.projectionList().add(…”),然后添加您选择的条款中的所有内容,我仍然无法理解,请您发布修改后的代码,这将有助于我理解更改。
        List result = session.createCriteria(teedObject.class)       
                .add(Restrictions.eq("syncSystem", syncSystem))
                .add(Restrictions.eq("hookId", hookId))
                .setProjection(Projections.projectionList()
                        .add(Projections.groupProperty("abcID"))
                        .add(Projections.count("abcID"))           
                ).list();