hibernate 使用笔记

public List findBySQL(final String queryString, final Class retrunCls,
            final Map queryArgs) throws DAORuntimeException {
  try {
   List result = (List) getHibernateTemplate().execute(
     new HibernateCallback() {
      public Object doInHibernate(Session session)
        throws HibernateException, SQLException {
       SQLQuery queryObject = session.createSQLQuery(queryString);
       queryObject.addEntity(retrunCls);
       // 设置查询参数
       setQueryParameters(queryObject, queryArgs);
       List listResult = queryObject.list();
       if (listResult == null)
        listResult = new ArrayList();
       return listResult;
      }
     });
   return result;
  } catch (Throwable ta) {
   log.warn("findBySQL [sql:" + queryString + ",queryArgs:"
     + queryArgs + "] Error:", ta);
   throw new DAORuntimeException(ta);
  }
 }

你可能感兴趣的:(hibernate,list,session,object,string,class)