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 付軒 閱讀(310) 評論(0)  編輯  收藏


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


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

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 平乡县| 西林县| 老河口市| 沁水县| 唐山市| 济宁市| 开阳县| 宁陕县| 张家港市| 白山市| 偏关县| 土默特左旗| 仁化县| 原阳县| 保靖县| 德清县| 新民市| 宜君县| 平果县| 金塔县| 措勤县| 海安县| 沐川县| 通化市| 凤冈县| 玉田县| 丰镇市| 漳平市| 富宁县| 商洛市| 大竹县| 陇南市| 玉树县| 丘北县| 徐闻县| 马尔康县| 贞丰县| 吉安市| 安达市| 徐水县| 绵阳市|