Hibernate.initialize

    public List<ChiefEditor> qbcByLikeName(final String preName) throws Exception {
        List retVal = (List) getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Criteria c = session.createCriteria(getEntityClazz());
                c.add(Restrictions.like(NAME,preName,MatchMode.START));
                List<ChiefEditor> list=c.list();
                for (ChiefEditor ce : list) {
                    //即使lazy=true,通过强制关联也可以获得多方的数据
                    Hibernate.initialize(ce.getBooks());
                }
                return list;
            }
        });
        return retVal;
    }

 

 

 

 

 

你可能感兴趣的:(C++,c,Hibernate,C#)