论坛首页 入门技术论坛

基于hibernate通用查询算法

浏览 1699 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-01-16  
/**
     * 带参数查询
     * @param querypath sql语句路径
     * @param args 参数--查询条件
     * @return result
     * @throws BussinessException
     */
    public List queryparam(String querypath,Object...args) throws BussinessException {
List list;
int i = 0;
        try {
            Session session = HbFactory.getSession();
            Transaction t=session.beginTransaction();
    Query query = session
    .getNamedQuery(querypath);
    for (Object obj : args) {
    query.setParameter(i, obj);
    i++;
    }
            list = query.list();
            t.commit();
        }catch(RuntimeException e){
        log.error(e);
        throw new BussinessException(e);
        } finally {
        HbFactory.closeSession();
        }
        return list;
    }
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics