views:

1170

answers:

3

Hello,

I'm trying to get only the list of id of object bob for example instead of the list of bob. It's ok with a HQL request, but I would know if it's possible using criteria ?

An example :

final StringBuilder hql = new StringBuilder();
hql.append( "select bob.id from " )
    .append( bob.class.getName() ).append( " bob " )
    .append( "where bob.id > 10");

final Query query = session.createQuery( hql.toString() );
return query.list();
+5  A: 

I think you could do that with Projections, something like

Criteria.forClass(bob.class.getName())
        .add(Restrictions.gt("id", 10))
        .setProjection(Projections.property("id"))
        );
agnul
+2  A: 

or setProjection(Projections.id())

jspinks