waterye

          hibernate的column級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麻煩, 并沒有測試

          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";
          不支持嵌套的對象, 不爽, 如
          String?hql?=?"select?new?Foo(f.id,?new?Bar(f.bar.id,?f.bar.name))?from?Foo?f";


          以上兩種方法在實際應用中都不是很理想, 但那種from Pojo的方式太浪費內存, 遇到blob字段更可怕, 有其他更好方法的請告知

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

          Feedback

          # re: hibernate的column級lazy 2007-04-08 21:41 rason

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

          主站蜘蛛池模板: 荃湾区| 武夷山市| 庆云县| 荆州市| 石景山区| 佛坪县| 聊城市| 游戏| 江阴市| 怀集县| 丽江市| 三河市| 高雄市| 普兰县| 崇州市| 罗山县| 桦甸市| 台中市| 长阳| 醴陵市| 全南县| 历史| 钟祥市| 紫云| 资源县| 长宁区| 溆浦县| 久治县| 南丹县| 吴忠市| 武川县| 南部县| 天水市| 辰溪县| 定西市| 镇沅| 汉沽区| 河北省| 陵水| 柯坪县| 陆丰市|