日期:2014-05-19  浏览次数:20992 次

hibernate3 属性 延迟加载 中的问题,请大家有知道的帮帮忙,谢谢。
detail属性是clob字段 ,所以我想让hibernate延迟加载该属性,下面是我的hibernate 中映射的配置 

Java code<property name="detail" lazy="true" type="org.springframework.orm.hibernate3.support.ClobStringType" column="detail" />


虽然设置了lazy="true",但是每次在批量抓取的时候hibernate还是会把clob字段读进来,大家帮忙看下问题出在哪呢?
Hibernate: 
  select
  this_.userID as userID0_0_,
  this_.loginName as loginName0_0_,
  this_.detail as detail0_0_ 
  from
  userinfo this_ 


映射文件中对特定的属性设置lazy,定义该属性为延迟载入。 

<hibernate-mapping>
<class name="org.cc.domain.UserInfo" table="userinfo">
<id name="userID" column="userID">
<generator class="identity" /></id>
 
<property name="loginName" column="loginName" />
<property name="detail" column="detail" 
type="org.springframework.orm.hibernate3.support.ClobStringType" lazy="true"/>
</class>
</hibernate-mapping>
属性的延迟载入要求在其代码构建时加入二进制指示指令(bytecode instrumentation),如果你的持久类代码中未含有这些指令, Hibernate将会忽略这些属性的延迟设置,仍然将其直接载入。 

在Ant的Task中,进行如下定义,对持久类代码加入“二进制指令。” 

<?xml version="1.0" encoding="UTF-8"?>
<project name="hibernateSample" default="instrument" basedir=".">
  <property name="lib.dir" value="./WebRoot/WEB-INF/lib"/>
  <property name="classes.dir" value="./WebRoot/WEB-INF/classes"/>
  <path id="lib.classes.path">
  <fileset dir="${lib.dir}">
  <include name="**/*.jar"/>
  </fileset>
  </path>
  <target name="instrument">
  <taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">
  <classpath path="${classes.dir}"/>
  <classpath path="lib.class.path"/>
  </taskdef>
  <instrument verbose="true">
  <fileset dir="${classes.dir}/org/cc/domain/">
  <include name="UserInfo.class"/>
  </fileset>
  </instrument>
  </target>
</project>


提示我:
BUILD FAILED
taskdef class org.hibernate.tool.instrument.InstrumentTask cannot be found

更新为一下:
classname="org.hibernate.tool.instrument.InstrumentTask"
classname="org.hibernate.tool.instrument.BasicInstrumentationTask"
classname="org.hibernate.tool.instrument.cglib.InstrumentTask"
classname="org.hibernate.tool.instrument.javassist.InstrumentTask"
还是提示以上失败信息




------解决方案--------------------
关注一下。。
------解决方案--------------------
延迟加载是不是针对对象的
------解决方案--------------------
延迟加载是针对对象的.
------解决方案--------------------
教你个简单方法 通过 select new 延迟加载
在你的dto 中建一个 构造方法 

String hql ="select new " + attachFile +
" (t1.docAttachFileOID,t1.fileName,t1.extName,t1.fileType,t1.extOID,t1.fileSize) from " + attachFile+" as t1 where t1.theExchangeDoc.exchangeDocOID = ?";
List list= hibernateOperations.find(hql, exchangeDocOID);