<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

             使用spring的HibernateTemplate 過程中發現有很多方法和直接使用hibernate 查詢的方法不同
    1、比如String hql = "select s from ShopInfo s where s.userId=:userid"; 這個hql語句 使用hibernate查詢
    Query query = this.getDaoDelegate().createQuery( hql ).setParameter("userid", userid);  這樣得到一個query了 可以通過setParameter方法寫對參數賦值,可是通過HibernateTemplate  如何進行查詢啊
    2、使用HibernateTemplate 的executeFind 和execute等方法的時候是返回一個HibernateCallback對象 要實現doInHibernate這個方法 這樣查詢的時候就都使用了一個匿名函數
    public List getAll(){
      return getHibernateTemplate().executeFind(new HibernateCallback() {
         public Object doInHibernate(Session s) {
            return s.createQuery("from Student").list();
          }
        });
     }
    感覺這樣很麻煩 有什么好的方法解決么 還請朋友多多指教 在線等

    posted on 2007-12-10 09:54 LifeNote 閱讀(5391) 評論(3)  編輯  收藏 所屬分類: Java 、Hibernate 、Spring
    Comments
    • # re: getHibernateTemplate() 學習的疑問
      ph
      Posted @ 2007-12-10 10:55
      //-------------------------------------------------------------------------
      // Convenience finder methods for HQL strings
      //-------------------------------------------------------------------------

      /**
      * Execute an HQL query.
      * @param queryString a query expressed in Hibernate's query language
      * @return a {@link List} containing the results of the query execution
      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
      * @see org.hibernate.Session#createQuery
      */
      List find(String queryString) throws DataAccessException;

      /**
      * Execute an HQL query, binding one value to a "?" parameter in the
      * query string.
      * @param queryString a query expressed in Hibernate's query language
      * @param value the value of the parameter
      * @return a {@link List} containing the results of the query execution
      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
      * @see org.hibernate.Session#createQuery
      */
      List find(String queryString, Object value) throws DataAccessException;

      /**
      * Execute an HQL query, binding a number of values to "?" parameters
      * in the query string.
      * @param queryString a query expressed in Hibernate's query language
      * @param values the values of the parameters
      * @return a {@link List} containing the results of the query execution
      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
      * @see org.hibernate.Session#createQuery
      */
      List find(String queryString, Object[] values) throws DataAccessException;

      /**
      * Execute an HQL query, binding one value to a ":" named parameter
      * in the query string.
      * @param queryString a query expressed in Hibernate's query language
      * @param paramName the name of the parameter
      * @param value the value of the parameter
      * @return a {@link List} containing the results of the query execution
      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
      * @see org.hibernate.Session#getNamedQuery(String)
      */
      List findByNamedParam(String queryString, String paramName, Object value)
      throws DataAccessException;

      /**
      * Execute an HQL query, binding a number of values to ":" named
      * parameters in the query string.
      * @param queryString a query expressed in Hibernate's query language
      * @param paramNames the names of the parameters
      * @param values the values of the parameters
      * @return a {@link List} containing the results of the query execution
      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
      * @see org.hibernate.Session#getNamedQuery(String)
      */
      List findByNamedParam(String queryString, String[] paramNames, Object[] values)
      throws DataAccessException;  回復  更多評論   
    • # re: getHibernateTemplate() 學習的疑問
      ph
      Posted @ 2007-12-10 11:05
      簡言之,用“?”的參數可以用find(hql, values), 用:userid可以使用findByNamedParam(hql, paramNames, values)  回復  更多評論   
    • # re: getHibernateTemplate() 學習的疑問
      LifeNote
      Posted @ 2007-12-10 17:07
      多謝指點 還是多看下api的好啊 呵呵   回復  更多評論   
     
    主站蜘蛛池模板: 久久高潮一级毛片免费| 男女猛烈无遮掩视频免费软件 | 国产免费观看a大片的网站| 看全免费的一级毛片| 亚洲精品午夜无码电影网| 亚洲免费观看在线视频| 亚洲精品无码mⅴ在线观看| 亚洲AⅤ永久无码精品AA| 久草视频在线免费看| 国产亚洲色视频在线| 1000部免费啪啪十八未年禁止观看 | 亚洲一区二区三区自拍公司| 每天更新的免费av片在线观看| 国产精品国产亚洲区艳妇糸列短篇| 超清首页国产亚洲丝袜| 中文字幕无码视频手机免费看 | 中文字幕免费视频| 黄色a三级免费看| 国产成人在线免费观看| 爱爱帝国亚洲一区二区三区| 久久精品国产亚洲香蕉| 一本久久综合亚洲鲁鲁五月天| 97精品免费视频| 国产精品偷伦视频免费观看了| 亚洲小说区图片区另类春色| 免费无码黄十八禁网站在线观看| 精品熟女少妇aⅴ免费久久 | 1000部无遮挡拍拍拍免费视频观看| 黄色片网站在线免费观看| 亚洲国产成人久久综合一区| av免费不卡国产观看| 99久久99这里只有免费的精品| 亚洲а∨精品天堂在线| 亚洲精品mv在线观看| 性色av免费观看| 免费A级毛片无码A∨中文字幕下载| h视频在线观看免费| 精品无码专区亚洲| 香蕉大伊亚洲人在线观看| 亚洲精品在线不卡| 久久久久亚洲精品美女|