DANCE WITH JAVA

          開發出高質量的系統

          常用鏈接

          統計

          積分與排名

          好友之家

          最新評論

          hibernate 3.2新的Session接口與之前接口的不同

          hibernate 3中的session接口的不同
          hibernate3.2版本中session出現了2個
          新session接口:org.hibernate.Session
          老session接口:org.hibernate.classic.Session
          顧名思義,classic包下的session就是以前常用的session,新的這個相比老的有很大變化。下邊詳細列出
          1,去掉了所有的find方法
          在新的session接口中沒有find方法,而在老的session接口中把find全部注釋成deprecated了。
          2,去掉所有的saveOrUpdateCopy,使用merge代替,這是classic.Session注釋中的一段原話.
          /**
            * Copy the state of the given object onto the persistent object with the same
            * identifier. If there is no persistent instance currently associated with
            * the session, it will be loaded. Return the persistent instance. If the
            * given instance is unsaved or does not exist in the database, save it and
            * return it as a newly persistent instance. Otherwise, the given instance
            * does not become associated with the session.
            *
            * @deprecated use {@link org.hibernate.Session#merge(String, Object)}
            *
            * @param object a transient instance with state to be copied
            * @return an updated persistent instance
            */
          注意這句:@deprecated use {@link org.hibernate.Session#merge(String, Object)}
          3,去掉了iterate方法
          給出的注釋是使用createQuery,自己獲得iterate
          4,去掉了filter方法
          @deprecated use {@link #createFilter(Object, String)}.{@link Query#list}
          給出的注釋說用createFilter代替,實際就是自己從createFilter獲得query然后自己查詢
          5,增加了一些方法
          具體自己看api吧,主要是提供了一些新的功能。
          總結:
          從上邊的改變不難看出hibernate對于接口的設定觀念改變了。

          以前的策略是:
          盡量給出全的接口,這樣減少用戶的代碼量,所以filter直接返回collection,iterate直接返回
          iterate。但這樣的結果是過度的提供接口,造成了學習上的負擔和選擇上的負擔。如何記住這些函數,如何在眾多函數
          中選擇是個麻煩事情。
          凡是做java的都知道,用一個java的東西最辛苦的是選擇,在開源的世界里邊選擇一個適合自己的工程,再在這個選擇的工程里邊選擇實現方法
          因為可能提供很多種實現方法,而且有些還是deprecated的。

          現在的策略:
          盡量簡化接口,或減少函數,或者簡化函數名,例如把saveOrUpdateCopy變成merge。
          這樣的好處是記憶學習負擔少。多寫幾句代碼不是特別麻煩。其實我個人來講更喜歡現在的感覺。
          以前的策略其實很大程度上是滿足程序員的個人需求,更有成就感。但確不適合使用者的需求。

          ok,無論如何現在的情況是更好了。

           

          posted on 2007-07-28 22:37 dreamstone 閱讀(8559) 評論(3)  編輯  收藏 所屬分類: dao層框架

          評論

          # re: hibernate 3.2新的Session接口與之前接口的不同 2010-07-07 16:38 淘寶網

          hibernate3.2版本中session出現了2個
          新session接口:org.hibernate.Session  回復  更多評論   

          # re: hibernate 3.2新的Session接口與之前接口的不同 2012-03-07 16:18 胡強

          學習了  回復  更多評論   

          # re: hibernate 3.2新的Session接口與之前接口的不同 2013-01-07 16:18 劉3

          剛知道,學習了  回復  更多評論   

          主站蜘蛛池模板: 海阳市| 黔西县| 靖宇县| 武鸣县| 金坛市| 旬邑县| 扬州市| 西充县| 新闻| 白山市| 察隅县| 元朗区| 无为县| 毕节市| 资中县| 祁阳县| 郁南县| 北安市| 房产| 桑日县| 石泉县| 宜宾县| 宁波市| 青龙| 雅安市| 凤阳县| 尉犁县| 宜宾县| 宁城县| 古浪县| 邵阳市| 隆尧县| 临邑县| 千阳县| 新巴尔虎右旗| 安义县| 来凤县| 荔波县| 连城县| 奉化市| 金寨县|