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));


» 本文章为Java地带原创,欢迎转载!转载请注明本文地址,谢谢!
» 本文链接:https://blog.java-zone.org/archives/1168.html
» 订阅本站:https://blog.java-zone.org/feed/
» 转载请注明来源:Java地带  » 《Hibernate条件查询:投影 分组 聚合 离线查询 子查询》

标签: Hibernate

添加新评论