junaidp
junaidp

Reputation: 11201

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

Upvotes: 4

Views: 16056

Answers (1)

mdonovan2010
mdonovan2010

Reputation: 423

Something like:

String result = (String)sess.createCriteria(Students.class)
    .add(Restrictions.eq("studentId",1))
    .setProjection(Property.forName('studentName'))
    .uniqueResult();

Upvotes: 5

Related Questions