hibernate 延遲加載問題

          If we want the publisher object can be accessed outside the session, there will be two possible
          solutions. One is to initialize the publisher explicitly, we can call the method Hibernate.initialize()
          for this task. This will force the publisher object to be loaded from database.
          Session session = factory.openSession();
          try {
          Book book = (Book) session.get(Book.class, id);
          Hibernate.initialize(book.getPublisher());
          return book;
          } finally {
          session.close();
          }
          Another solution is to turn off the lazy initialization feature for this association. This may decrease
          the performance as the publisher object will be loaded together with the book object every time.
          <hibernate-mapping package="mo.org.cpttm.bookshop">
          <class name="Book" table="BOOK">
          ...
          <many-to-one name="publisher" class="Publisher" column="PUBLISHER_ID"
          lazy="false" />
          </class>
          </hibernate-mapping>

          posted on 2007-07-03 17:23 付軒 閱讀(316) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年7月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 五台县| 宁河县| 惠东县| 从江县| 铅山县| 庆城县| 磐安县| SHOW| 锦屏县| 墨竹工卡县| 澄城县| 治多县| 察哈| 沙河市| 绥德县| 木里| 南木林县| 昂仁县| 天柱县| 井冈山市| 孙吴县| 桓仁| 屏山县| 兰西县| 保山市| 镇平县| 河东区| 炉霍县| 龙泉市| 正安县| 花莲县| 临澧县| 日喀则市| 鹤岗市| 华安县| 澄城县| 江城| 秦皇岛市| 河南省| 舒城县| 增城市|