Hibernate条件查询:投影 分组 聚合 离线查询 子查询

List results = session.createCriteria(Cat.class)
    .setProjection( Projections.rowCount() )
    .add( Restrictions.eq("color", Color.BLACK) )
    .list();
List results = session.createCriteria(Cat.class)
    .setProjection( Projections.projectionList()
        .add( Projections.rowCount() )
        .add( Projections.avg("weight") )
        .add( Projections.max("weight") )
        .add( Projections.groupProperty("color") )
    )
    .list();

/////////////////////////////////////////////////////////

List results = session.createCriteria(Cat.class)
    .setProjection( Projections.alias( Projections.groupProperty("color"), "colr" ) )
    .addOrder( Order.asc("colr") )
    .list();
List results = session.createCriteria(Cat.class)
    .setProjection( Projections.groupProperty("color").as("colr") )
    .addOrder( Order.asc("colr") )
    .list();

/////////////////////////////////////////////////////////

DetachedCriteria dctr = DetachedCriteria.forClass( Affiliate.class );
dctr.setProjection(Property.forName("trackerId"));
dctr.add( Restrictions.like("affiliate", affiliate, MatchMode.ANYWHERE ) );
ctr.add( Subqueries.propertyIn("trackerId", dctr));

标签: Hibernate条件查询

添加新评论