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

后端 未结 7 1033
攒了一身酷
攒了一身酷 2020-12-29 19:54

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 ?

7条回答
  •  再見小時候
    2020-12-29 20:12

    You can do that like this

        bob bb=null;
    
        Criteria criteria = session.createCriteria(bob.class);  
        criteria.add(Restrictions.eq("id",id));
    
        bb = (bob) criteria.uniqueResult();
    

    as Restrictions you can add your condition

提交回复
热议问题