java - Hibernate select lowest value greater than -


i trying hibernate return object has lowest id number greater value.

the code have returning integer though, instead of object.

code

criteria criteria = session.createcriteria(story.class); criterion storyid = restrictions.ge("id", 2); projectionlist projlist = projections.projectionlist(); projlist.add(projections.min("id")); criteria.add(storyid); criteria.setprojection(projlist); list<?> storyresult = criteria.list(); session.close();             story story = (story) storyresult.get(0); 

right returning "3" integer. 3 next available id, why hibernate giving me integer instead of object?

thanks

by adding projection, asking hibernate change query select * table select min(id) table query. that's 1 of features of projection.

to achieve want achieve, need use projection id , use query retrieve object.

criteria idquery = session.createcriteria(story.class); idquery.add(restrictions.ge("id", 2)); idquery.setprojection(projections.min("id")); int returnedid = criteria.uniqueresult();  criteria storyquery = session.createcriteria(story.class); storyquery.add(restrictions.ideq(returnedid); story story = (story) storyquery.uniqueresult(); return story; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -