Hibernate中用Projection实现Lazy loading

Hibernate中用Projection实现Lazy loading
        Class classT  =  SequestPeptide. class ;

        Criteria criteria 
=  arg0.createCriteria(classT,  " p " );
        criteria.add(Restrictions.eq(
" project.id " , projectId));
        criteria.setFirstResult(startRecord);
        criteria.setFetchSize(recordCount);
        criteria.setMaxResults(recordCount);
        criteria.addOrder(Order.asc(
" peptide " ));

        Projection projection
= Projections.projectionList()
        .add( Projections.property(
" p.id " ),  " id "  )
        .add( Projections.property(
" p.peptide " ),  " peptide "  )
        .add( Projections.property(
" p.dtaFilename " ),  " dtaFilename "  )
        .add( Projections.property(
" p.outFilename " ),  " outFilename "  );
        criteria.setProjection(projection).setResultTransformer( 
new  AliasToBeanResultTransformer(classT) );
        
return  criteria.list();



你可能感兴趣的:(Hibernate中用Projection实现Lazy loading)