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:
None.gif < target  name ="instrument"  depends ="compile" >
None.gif    
< taskdef  name ="instrument"  classname ="org.hibernate.tool.instrument.InstrumentTask" >
None.gif        
< classpath  path ="${jar.path}" />
None.gif        
< classpath  path ="${classes.dir}" />
None.gif        
< classpath  refid ="lib.class.path" />
None.gif    
</ taskdef >
None.gif
None.gif    
< instrument  verbose ="true" >
None.gif        
< fileset  dir ="${testclasses.dir}/org/hibernate/auction/model" >
None.gif            
< include  name ="*.class" />
None.gif        
</ fileset >
None.gif    
</ instrument >
None.gif
</ 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

None.gif //  use vo
None.gif
String hql  =   " select new Foo(f.id, f.name) from Foo f " ;
None.gif
None.gif
//  use map 
None.gif
String hql  =   " select new map(f.id, f.name) from Foo f " ;
None.gif
None.gif
//  use Object[]
None.gif
String hql  =   " select f.id, f.name from Foo f " ;
None.gif
None.gif
//  use list
None.gif
String  " select new list(f.id, f.name) from Foo f " ;
不支持嵌套的对象, 不爽, 如
None.gif String hql  =   " select new Foo(f.id, new Bar(f.bar.id, f.bar.name)) from Foo f " ;


以上两种方法在实际应用中都不是很理想, 但那种from Pojo的方式太浪费内存, 遇到 blob字段更可怕, 有其他更好方法的请告知 40316.html

water ye 2006-04-10 20:28 发表评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值