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 ?
SessionFactory sessionFactory;
Criteria crit=sessionFactory.getCurrentSession().createCriteria(Model.class);
crit.setProjection(Projections.property("id"));
List result = crit.list();
This code code will give you list of ids in the model class like [1,2,3]
.
if you wants to get the array list like [{"id":1},{"id":2}]
then use the following code
SessionFactory sessionFactory;
Criteria crit=sessionFactory.getCurrentSession().createCriteria(Model.class);
crit.setProjection(Projections.property("id").as("id"));
List result = crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();