<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的好啊 呵呵   回復  更多評論   
     
    主站蜘蛛池模板: 污污网站免费观看| 国产天堂亚洲国产碰碰| 久久香蕉国产线看免费| 亚洲欧美综合精品成人导航| 在线看片免费人成视久网| 亚洲AV乱码久久精品蜜桃| 日韩精品无码免费专区午夜 | 亚洲欧美国产精品专区久久| 动漫黄网站免费永久在线观看| 国产精品久免费的黄网站| 亚洲国产欧美国产综合一区 | 2015日韩永久免费视频播放| 亚洲色成人网一二三区| 久久久久久影院久久久久免费精品国产小说 | 亚洲人成网站在线观看青青| 老司机午夜在线视频免费| 国产亚洲?V无码?V男人的天堂 | 亚洲欧美在线x视频| 亚洲日本中文字幕一区二区三区| 深夜特黄a级毛片免费播放| 中文字幕第一页亚洲| 久久精品人成免费| 亚洲色成人WWW永久在线观看| 日本免费观看网站| 精品一区二区三区免费观看 | 亚洲无人区码一二三码区别图片 | 98精品全国免费观看视频| 亚洲中文无码a∨在线观看| 国产精品久久久久影院免费| 精品免费久久久久国产一区 | 久久午夜夜伦鲁鲁片免费无码| 亚洲手机中文字幕| 成全动漫视频在线观看免费高清版下载| 亚洲av无码成h人动漫无遮挡 | 亚洲综合无码无在线观看| 国产成人精品久久亚洲| 人与禽交免费网站视频| 美女羞羞视频免费网站| 亚洲视频在线观看网站| 亚洲AV中文无码乱人伦| 日本免费xxxx|