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


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


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

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金湖县| 温泉县| 讷河市| 闵行区| 澄迈县| 南木林县| 含山县| 濮阳市| 离岛区| 内丘县| 清徐县| 海原县| 库伦旗| 天水市| 汉中市| 京山县| 临安市| 祁东县| 抚远县| 南投县| 永州市| 紫阳县| 上犹县| 砚山县| 宜春市| 松滋市| 罗城| 仪征市| 三穗县| 安新县| 涡阳县| 通许县| 天等县| 华蓥市| 麦盖提县| 岫岩| 临猗县| 台东县| 来宾市| 崇义县| 泰来县|