使用 HibernateTemplate 实现分页查询 (HibernateCallback接口)
来源:互联网 发布:ipad看淘宝不能横屏 编辑:程序博客网 时间:2024/03/29 05:57
/**
*
*/
package springdao;
import hibernatedao.HibernateSessionFactory;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
* 通用 DAO 包
* @author kiant
* @version Sep 7, 2008
*/
public class CommomsDAO {
private static final Log log = LogFactory.getLog(EcOpusDAO.class);
//获得会话
private static HibernateTemplate hibernateTemplate = new HibernateTemplate(HibernateSessionFactory.getSessionFactory());
/**
* 分页通用方法
* @param hql HQL查询语句
* @param offset 起始记录下标
* @param lengh 读取记录数
* @return List 结果集
*/
public static List getListForPage(final String hql, final int offset, final int lengh) {
log.debug("finding ListForPage");
try {
List list = hibernateTemplate.executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List list2 = session.createQuery(hql)
.setFirstResult(offset)
.setMaxResults(lengh)
.list();
return list2;
}});
return list;
} catch (RuntimeException re) {
log.error("find ListForPage failed", re);
throw re;
}
}
}
*
*/
package springdao;
import hibernatedao.HibernateSessionFactory;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
* 通用 DAO 包
* @author kiant
* @version Sep 7, 2008
*/
public class CommomsDAO {
private static final Log log = LogFactory.getLog(EcOpusDAO.class);
//获得会话
private static HibernateTemplate hibernateTemplate = new HibernateTemplate(HibernateSessionFactory.getSessionFactory());
/**
* 分页通用方法
* @param hql HQL查询语句
* @param offset 起始记录下标
* @param lengh 读取记录数
* @return List 结果集
*/
public static List getListForPage(final String hql, final int offset, final int lengh) {
log.debug("finding ListForPage");
try {
List list = hibernateTemplate.executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List list2 = session.createQuery(hql)
.setFirstResult(offset)
.setMaxResults(lengh)
.list();
return list2;
}});
return list;
} catch (RuntimeException re) {
log.error("find ListForPage failed", re);
throw re;
}
}
}
- 使用 HibernateTemplate 实现分页查询 (HibernateCallback接口)
- 使用 HibernateTemplate 实现分页查询
- 使用 HibernateTemplate 实现分页查询
- 使用 HibernateTemplate 实现分页查询
- hql分页( HibernateCallback接口 )
- HibernateTemplate中HibernateCallback的事务 为什么需要使用HibernateCallback
- 扩展HibernateTemplate,实现分页查询 (回调)
- 对hibernateTemplate 类的 方法中使用 new HibernateCallback()接口形象doInHibernate()方法的理解
- 使用 HibernateTemplate 实现分页查询 和其使用的策略模式
- hibernateTemplate 模糊分页查询
- 使用hibernate和hibernateTemplate实现分页
- HibernateTemplate实现分页
- hibernateTemplate实现分页
- HibernateTemplate实现分页
- HibernateTemplate实现分页
- hibernateTemplate实现分页
- HibernateTemplate实现分页
- HibernateTemplate实现分页
- SQL语句里连接其它服务器上的数据库(通过TCP/IP),并操作和读取?
- 内部类
- 关于Debug和Release之本质区别的讨论本文主要包含如下内容:
- Ubuntu Linux 下安装配置Django
- PHP Fatal error: Call to undefined function pg_connect()
- 使用 HibernateTemplate 实现分页查询 (HibernateCallback接口)
- 代码坏味道,重构与模式
- Android杂谈---获取手机屏幕大小
- 畅想曲
- 程序发布批号规则
- v$session,v$session_wait,v$session_wait_history,v$active_session_history
- 接口规范
- oracle: OCA-042-题解与实验(1)
- BIOS中断—直接磁盘服务(Direct Disk Service——INT 13H)