本站首页    管理页面    写新日志    退出


«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7647002
建立时间:2006年5月29日




[Hibernate]hibernate的column级lazy
软件技术,  电脑与网络

lhwork 发表于 2006/6/15 10:46:39

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: 500)this.width=500'><target name="instrument" depends="compile">500)this.width=500'>    <taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">500)this.width=500'>        <classpath path="${jar.path}"/>500)this.width=500'>        <classpath path="${classes.dir}"/>500)this.width=500'>        <classpath refid="lib.class.path"/>500)this.width=500'>    </taskdef>500)this.width=500'>500)this.width=500'>    <instrument verbose="true">500)this.width=500'>        <fileset dir="${testclasses.dir}/org/hibernate/auction/model">500)this.width=500'>            <include name="*.class"/>500)this.width=500'>        </fileset>500)this.width=500'>    </instrument>500)this.width=500'></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 hql500)this.width=500'>// use vo500)this.width=500'>String hql = "select new Foo(f.id, f.name) from Foo f";500)this.width=500'>500)this.width=500'>// use map 500)this.width=500'>String hql = "select new map(f.id, f.name) from Foo f";500)this.width=500'>500)this.width=500'>// use Object[]500)this.width=500'>String hql = "select f.id, f.name from Foo f";500)this.width=500'>500)this.width=500'>// use list500)this.width=500'>String "select new list(f.id, f.name) from Foo f";不支持嵌套的对象, 不爽, 如 500)this.width=500'>String hql = "select new Foo(f.id, new Bar(f.bar.id, f.bar.name)) from Foo f";以上两种方法在实际应用中都不是很理想, 但那种from Pojo的方式太浪费内存, 遇到blob字段更可怕, 有其他更好方法的请告知


阅读全文(2127) | 回复(-1) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.125 second(s), page refreshed 144813390 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号