使用scrollableResults

时间:2015-08-12 21:39:40

标签: java sql hibernate hibernate-criteria

我有一个dao方法。

    public ScrollableResults getPRecord(StatelessSession statelessSession) throws UnsupportedEncodingException{
    Criteria crit = statelessSession.createCriteria(APRecord.class, "apr");
    crit.createAlias("mAiD", "aID", Criteria.INNER_JOIN);


    crit.addOrder( Order.asc("pName") );
    crit.addOrder( Order.asc("kNum") );
    return crit.scroll(ScrollMode.FORWARD_ONLY);
    }

这会返回重复的结果,所以我写了一个sql查询,摆脱了重复的结果。(我试过DISTINCT_ROOT_ENTITY,它不起作用)。

sql查询以避免重复:

     select this_.pName as y0_,
     this_.kNum as y1_, 
     this_.agentG as y2_, 
     count(distinct aId1_.aID) as y3_ 
     from APS_ACCM_CurrentPatchesView this_ 
     inner join APS_ACCM_ManagedAssetsView
     aId1_ on this_. agentG = aId1_. agentG
     group by this_. pName, this_.kNum, this_.agentG

如何在Hibernate中编写此代码? Innerjoin让我很难过。

0 个答案:

没有答案