hibernate where clause with projection
开发者_开发技巧There's a table name STUDENTS with column studentName and studentID
I want to run a query like
SELECT studentName
FROM STUDENTS
WHERE studentId ='1';
in hibernate criteria and want to save this result in some String variable
Something like:
String result = (String)sess.createCriteria(Students.class)
.add(Restrictions.eq("studentId",1))
.setProjection(Property.forName('studentName'))
.uniqueResult();
精彩评论