waterye

          hibernate的column級(jí)lazy

          1. Using lazy property fetching
          To enable lazy property loading, set the lazy attribute on your particular property mappings:
          <class?name="Document">
          ???????
          <id?name="id">
          ????????
          <generator?class="native"/>
          ????
          </id>
          ????
          <property?name="name"?not-null="true"?length="50"/>
          ????
          <property?name="summary"?not-null="true"?length="200"?lazy="true"/>
          ????
          <property?name="text"?not-null="true"?length="2000"?lazy="true"/>
          </class>

          Lazy property loading requires buildtime bytecode instrumentation! If your persistent classes are not enhanced, Hibernate will silently ignore lazy property settings and fall back to immediate fetching.

          For bytecode instrumentation, use the following Ant task:
          <target?name="instrument"?depends="compile">
          ????
          <taskdef?name="instrument"?classname="org.hibernate.tool.instrument.InstrumentTask">
          ????????
          <classpath?path="${jar.path}"/>
          ????????
          <classpath?path="${classes.dir}"/>
          ????????
          <classpath?refid="lib.class.path"/>
          ????
          </taskdef>

          ????
          <instrument?verbose="true">
          ????????
          <fileset?dir="${testclasses.dir}/org/hibernate/auction/model">
          ????????????
          <include?name="*.class"/>
          ????????
          </fileset>
          ????
          </instrument>
          </target>

          Please note that this is mostly a marketing feature, as in practice, optimizing row reads is much more important than optimization of column reads.

          debug麻煩, 并沒(méi)有測(cè)試

          2. use hql

          //?use?vo
          String?hql?=?"select?new?Foo(f.id,?f.name)?from?Foo?f";

          //?use?map?
          String?hql?=?"select?new?map(f.id,?f.name)?from?Foo?f";

          //?use?Object[]
          String?hql?=?"select?f.id,?f.name?from?Foo?f";

          //?use?list
          String?"select?new?list(f.id,?f.name)?from?Foo?f";
          不支持嵌套的對(duì)象, 不爽, 如
          String?hql?=?"select?new?Foo(f.id,?new?Bar(f.bar.id,?f.bar.name))?from?Foo?f";


          以上兩種方法在實(shí)際應(yīng)用中都不是很理想, 但那種from Pojo的方式太浪費(fèi)內(nèi)存, 遇到blob字段更可怕, 有其他更好方法的請(qǐng)告知

          posted on 2006-04-10 20:28 waterye 閱讀(2017) 評(píng)論(1)  編輯  收藏 所屬分類: hibernate

          Feedback

          # re: hibernate的column級(jí)lazy 2007-04-08 21:41 rason

          采用Hibernate annotation(JPA)
          @Lob
          @Basic(fetch=LAZY)
          private byte[] fileContent;  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 普安县| 萨迦县| 伽师县| 惠来县| 赣榆县| 越西县| 罗城| 增城市| 织金县| 务川| 娄底市| 丹江口市| 当雄县| 白银市| 平定县| 浑源县| 滦平县| 泸水县| 惠州市| 青田县| 肥乡县| 昌宁县| 建阳市| 兴和县| 全州县| 陈巴尔虎旗| 荆门市| 桃园市| 泰宁县| 浪卡子县| 辰溪县| 文安县| 泰和县| 广宁县| 中宁县| 西城区| 敖汉旗| 博客| 新巴尔虎左旗| 富顺县| 旺苍县|