今天才知道hibernate原来对mysql中limit这个功能是不支持的,只能采用setMaxResults来实现

具体实现方法如下:

public List<Propertyhistory> getHistoryByServiceAndMeta(Integer serviceId, Integer metaId, Integer limitNum)
{
final Integer maxNum = limitNum;
final String sql = “from Propertyhistory where serviceId=”+serviceId+” and metaId=”+metaId+”  order by modifiedTime DESC”;
List<Propertyhistory> list = super.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
return session.createQuery(sql).setMaxResults(maxNum).list();
}

});
return list;
}

本文地址:http://www.yaronspace.cn/blog/index.php/archives/333

来自yaronspace.cn  本文链接:http://yaronspace.cn/blog/archives/333