如何使用criteria
或HQL
查询获取表格的第一行?
表格创建脚本
CREATE TABLE MonthlySubscriber(MSISDN bigint(20)
NOT NULL, MonthOfYear int(11) NOT NULL,
PRIMARY KEY (MSISDN));
答案 0 :(得分:24)
是的,您可以使用setMaxResults
&标准中的setFirstResult
示例代码
Criteria queryCriteria = session.createCriteria(MonthlySubscriber.class);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
monthlySubscriberList = queryCriteria .list();
答案 1 :(得分:0)
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();
答案 2 :(得分:0)
Criteria queryCriteria = currentSession.createCriteria(Project.class);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
entity = (Project) queryCriteria.uniqueResult(); // Casting to the Entity class
答案 3 :(得分:-1)
public Criteria setFirstResult(int firstResult)
此方法采用一个整数表示结果集中的第一行,从第0行开始。REFER