0

Here is my code,

Criteria criteria = session.createCriteria(Category.class);     
        criteria.add(Restrictions.eq("id", 102));
            criteria.setProjection(Projections.projectionList().add(Projections.property("item")).add((Projections.alias(Projections.count("item.itemId"), "itemsCount"))));
    criteria.addOrder(Order.desc("itemsCount"));

    List<items> items = criteria.list();

Thanks a lot !

Naveen A
  • 533
  • 4
  • 8
  • 16
  • What are you trying to do? Can you publish the SQL you want to use. I am not sure if you can use **count(itemId)** with out a group by clause. – ManuPK Dec 29 '11 at 05:45
  • I just need all categories order by number of items, itemId is referenced column in categories. – Naveen A Dec 29 '11 at 05:51

1 Answers1

0

not directly possible with criteria

using hql

using a formula property (probably with a NOOP implementation of ISetter as access if you definitly dont want the property in your class)

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94