hibernate doInHibernate 用法

1:executeFind

public List findRowList(final String queryString, final int rows) {

returngetHibernateTemplate().executeFind(newHibernateCallback(){

publicObjectdoInHibernate(Sessionsession)throwsHibernateException{

Queryq=session.createQuery(queryString);

q.setFirstResult(0);

q.setMaxResults(rows);

Listlist=q.list();

if(list==null){

list=Collections.EMPTY_LIST;

}

returnlist;

}

});

    }

2:   protected Integer queryCount(final QueryCondition condition) throws ScriptException {

try{

return(Integer)getHibernateTemplate().execute(newHibernateCallback(){

publicObjectdoInHibernate(Sessionsession)throwsHibernateException{

Queryq=createQuery(session,condition);

Listlist=q.list();

if(list==null){

returnnewInteger(0);

}else{

return(Integer)list.get(0);

                   }

               }

});

       } catch (Exception e) {

           throw new ScriptException(e);

}

    }

3:try {

return(DMTask)getHibernateTemplate().execute(newHibernateCallback(){

publicObjectdoInHibernate(Sessionsession)throwsHibernateException{

DMTaskt=null;

Queryq=session.createQuery(query)

.setFirstResult(0)

.setMaxResults(1);

Listresult=q.list();

if(result!=null&&result.size()>0){

t=(DMTask)result.get(0);

}

returnt;

}

});

}catch(DataAccessExceptione){

thrownewDAOException(e);

        }  

相关推荐