getting first row of table by criteria query
Criteria queryCriteria = currentSession.createCriteria(Project.class);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
entity = (Project) queryCriteria.uniqueResult(); // Casting to the Entity class
Yes you can do that with setMaxResults
& setFirstResult
in criteria
Sample Code
Criteria queryCriteria = session.createCriteria(MonthlySubscriber.class);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
monthlySubscriberList = queryCriteria .list();
you could do that like this:
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
String sql= "select b.wcd, a.optime from UseWaterRecord a, WellBasicInfo b where a.stcd=:a_stcd and b.stcd=:b_stcd ORDER BY a.optime desc";
Query query = session.createQuery(sql);
query.setString("a_stcd", "10100405");
query.setString("b_stcd", "10100405");
query.setFirstResult(0);
query.setMaxResults(1);
List wrwmList = query.list();