Hibernate 编写条件/休眠查询时出现问题?

Hibernate 编写条件/休眠查询时出现问题?,hibernate,criteria,hibernate-criteria,Hibernate,Criteria,Hibernate Criteria,如何在条件查询和hibernate查询中编写以下sql查询 sql查询如下: SELECT * FROM table1 ORDER BY testId DESC LIMIT 1; 我写道: Criteria tobaccoID = sessionFactory.getCurrentSession().createCriteria(table1.class); tobaccoID.add(Restrictions.eq("surveyId",send_Survey)); tobaccoID.ad

如何在条件查询和hibernate查询中编写以下sql查询

sql查询如下:

SELECT * FROM table1 ORDER BY testId DESC LIMIT 1;
我写道:

Criteria tobaccoID = sessionFactory.getCurrentSession().createCriteria(table1.class);
tobaccoID.add(Restrictions.eq("surveyId",send_Survey));
tobaccoID.addOrder(Order.desc("testId")); // How can I specify the limit 1 here
tobaccoID.add(Restrictions.eq("algorithmno", lifeStyleHabbitsOne));
tobaccoID.add(Restrictions.eq("stringno", "01"));
ScrollableResults tobaccoIDP=tobaccoID.scroll();
但我不知道我怎么能在这里设定限制


任何建议。

类似于coID.setMaxResults1;这不符合我的要求。我已经在下面的链接中清楚地解释了我的问题。请给我一个这样做的建议。