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

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

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

             使用spring的HibernateTemplate 過程中發(fā)現(xiàn)有很多方法和直接使用hibernate 查詢的方法不同
    1、比如String hql = "select s from ShopInfo s where s.userId=:userid"; 這個(gè)hql語句 使用hibernate查詢
    Query query = this.getDaoDelegate().createQuery( hql ).setParameter("userid", userid);  這樣得到一個(gè)query了 可以通過setParameter方法寫對參數(shù)賦值,可是通過HibernateTemplate  如何進(jìn)行查詢啊
    2、使用HibernateTemplate 的executeFind 和execute等方法的時(shí)候是返回一個(gè)HibernateCallback對象 要實(shí)現(xiàn)doInHibernate這個(gè)方法 這樣查詢的時(shí)候就都使用了一個(gè)匿名函數(shù)
    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 閱讀(5384) 評論(3)  編輯  收藏 所屬分類: Java 、Hibernate 、Spring
    Comments
    • # re: getHibernateTemplate() 學(xué)習(xí)的疑問
      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;  回復(fù)  更多評論   
    • # re: getHibernateTemplate() 學(xué)習(xí)的疑問
      ph
      Posted @ 2007-12-10 11:05
      簡言之,用“?”的參數(shù)可以用find(hql, values), 用:userid可以使用findByNamedParam(hql, paramNames, values)  回復(fù)  更多評論   
    • # re: getHibernateTemplate() 學(xué)習(xí)的疑問
      LifeNote
      Posted @ 2007-12-10 17:07
      多謝指點(diǎn) 還是多看下api的好啊 呵呵   回復(fù)  更多評論   
     
    主站蜘蛛池模板: 中文字幕天天躁日日躁狠狠躁免费| 日韩在线永久免费播放| 国产亚洲精品高清在线| a国产成人免费视频| 亚洲资源在线视频| 国产成人免费ā片在线观看| 一本久久A久久免费精品不卡| 亚洲一区二区三区成人网站| 日韩一区二区免费视频| 国产精品免费久久| 亚洲av日韩av综合| 精品亚洲成α人无码成α在线观看 | 亚洲AV无码一区二区三区网址 | 三上悠亚在线观看免费| 亚洲精品在线电影| 亚洲AV无码成人精品区大在线| 久久国产免费一区二区三区| 亚洲精品无码国产片| 亚洲VA成无码人在线观看天堂| 在线观看免费宅男视频| 国产午夜成人免费看片无遮挡| 亚洲午夜无码久久| 1区1区3区4区产品亚洲| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 免费无码国产V片在线观看| 亚洲综合无码一区二区| 亚洲综合最新无码专区| 成人男女网18免费视频| 国产va在线观看免费| 一区二区在线视频免费观看| 学生妹亚洲一区二区| 久久青草亚洲AV无码麻豆| 亚洲无码视频在线| 免费黄色一级毛片| 国产在线jyzzjyzz免费麻豆 | 91高清免费国产自产| h视频在线免费观看| 成人婷婷网色偷偷亚洲男人的天堂 | 亚洲七七久久精品中文国产| 免费无码A片一区二三区| 67194国产精品免费观看|