How to use hibernate criteria to return only one element of an object instead the entire object? -


i'm trying list of id of object bob example instead of list of bob. it's ok hql request, know if it's possible using criteria ?

an example :

final stringbuilder hql = new stringbuilder(); hql.append( "select bob.id " )     .append( bob.class.getname() ).append( " bob " )     .append( "where bob.id > 10");  final query query = session.createquery( hql.tostring() ); return query.list(); 

i think projections, like

criteria.forclass(bob.class.getname())         .add(restrictions.gt("id", 10))         .setprojection(projections.property("id"))         ); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -