Hibernate Custom Order By Query -
public list<t> findrange(int start, int duration) { session hibernatesession = this.getsession(); list<t> results = null; try { hibernatesession.begintransaction(); query q = hibernatesession.createquery("from " + type.getsimplename() ); q.setfirstresult(start); q.setmaxresults(duration); results = q.list(); hibernatesession.gettransaction().commit(); } { hibernatesession.close(); } return results; }
i have above query gets row range database me, need retrieve them ordered on jobstatus column, , not alphabetically or numerically following importance:
case "open": return 1; break; case "on hold": return 2; break; case "offer extended": return 3; break; case "closed": return 4; break;
how can rework hibernate query if want rows 10 through 20, retrieve them table in order?
to generically, don't think you'll away less than;
query q = hibernatesession.createquery("from " + type.getsimplename() + " order case when jobstatus='open' 1 " + "when jobstatus='on hold' 2 " + "when jobstatus='offer extended' 3 " + "when jobstatus='closed' 4 " "else 5 end, id");
Comments
Post a Comment