您的位置:首页 > 其它

One-root-entity-per-returned-row phenomenon of hibernate

2007-05-16 14:39 148 查看
 




public static List t() ...{


        List r = new ArrayList();


        Session s = Sf.getSession();


        Transaction tx;


        tx = s.beginTransaction();


        String sql;






        try ...{


            r = s.createCriteria(JtsUser.class)


                 .add(Restrictions.idEq(2))


                 .setFetchMode("jtsHistories", FetchMode.JOIN)


                 .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)


                 .list();


            tx.commit();




        } catch (Exception e) ...{


            e.printStackTrace();


            tx.rollback();




        } finally ...{


            s.close();


        }


        return r;


    }


    






    public static List tt() ...{


        List r = new ArrayList();


        Session s = Sf.getSession();


        Transaction tx;


        tx = s.beginTransaction();


        String sql;






        try ...{


            r = s.createCriteria(JtsUser.class)


                 .add(Restrictions.idEq(2))


                 .setFetchMode("jtsHistories", FetchMode.JOIN)


                 .list();


            tx.commit();




        } catch (Exception e) ...{


            e.printStackTrace();


            tx.rollback();




        } finally ...{


            s.close();


        }


        return r;


    }

t().size() is 1; While tt().size() is 4, that's the one-root-entity-per-returned-row phenomenon of hibernate.

Add "setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)" to eliminate the one-root-entity-per-returned-row phenomenon that you're seeing. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate class
相关文章推荐