小鱼的空气

记录我所思

Hibernate lazy load clob field

Hibernate的Lazy load是很深得人心的,再配合使用Spring的OpenSessionInviewFilter基本可以减少很多劳累的工作。 Clob和Blob是两个经常用的数据库类型,也是查询的杀手,在数据量上到一万条以上,就就算你是执行一个只有十条记录的分页查询,也得用上几秒,Clob字段更加不敢用like查询,时间长到你实在无法忍受,当然可以选择全文检索工具如Lucene。上面的问题自然要解决,方法可能很多,下面是其中一种,即对简单属性也 lazy load .

1. 编码,对相应的hbm.xml或annotation对该属性加上lazy=true或@Basic(fetch = FetchType.LAZY).
2. 编译,对编译后的Model Class进行字节码织入,Hibernate已经提供了工具类,拿来运行即可,Ant脚本如下:

    <target name="instrument">
        
<taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">
            
<classpath path="${classes.dir}"/>
            
<classpath refid="project.classpath"/>
        
</taskdef>

        
<instrument verbose="true">
            
<fileset dir="${classes.dir}/com/gdsoftpark/cms/model">
                
<include name="*.class"/>
            
</fileset>
            
<fileset dir="${classes.dir}/com/gdsoftpark/common/core/base">
                
<include name="Model.class"/>
            
</fileset>
        
</instrument>
    
</target>
3. 运行,从生成的SQL你可以看到某些字段确实Lazy load了。

posted on 2007-06-05 14:55 小鱼 阅读(901) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(3)

我参与的团队

随笔档案

文章档案

搜索

最新评论