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字段更可怕, 有其他更好方法的請告知