facebook

Post subject: Problems of Using lazy property fetching

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #297222 Reply

    bijiasuo
    Member

    There is one property in my VO,and I want to set this property “lazy”.
    I have read the doc about this in this forum.here it is:
    —————————————————————————
    Hibernate3 supports the lazy fetching of individual properties. This optimization technique is also known as fetch groups. Please note that this is mostly a marketing feature, as in practice, optimizing row reads is much more important than optimization of column reads. However, only loading some properties of a class might be useful in extreme cases, when legacy tables have hundreds of columns and the data model can not be improved.

    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>

    ————————————————————————–
    So, I have followed what I have mentioned above.
    here is my column definition in xml file:
    <property generated=”never” lazy=”true” name=””””content”””” type=”java.lang.String”>
    <column length=”65535″ name=””””content”/>
    “” </property>

    here is my build.xml file,which is in the WEB-INF folder:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <project basedir=”.” default=”build” name=””””network2009back”>
    “” <property name=””””lib.dir”””” value=”./lib” />
    <property name=””””classes.dir”””” value=”./classes” />

    <path id=”lib.class.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 refid=”lib.class.path” />
    </taskdef>

    <instrument verbose=”true”>
    <fileset dir=”${classes.dir}/com/vo/bbs”>
    <include name=””””*.class”””” />
    </fileset>
    </instrument>
    </target>
    </project>

    so,problem No.1 comes out.the class when myeclipse is anting the build.xml file,the class “org.hibernate.tool.instrument.InstrumentTask” cannot be found.So I use “org.hibernate.tool.instrument.cglib.InstrumentTask” in stead of “org.hibernate.tool.instrument.InstrumentTask”.
    This time the building works.
    The message in concole window is just like this:
    Buildfile: E:\学习\我的java实验\MyEclipse7WS\network2009back\WebRoot\WEB-INF\build.xml
    instrument:
    [instrument] starting instrumentation
    [instrument] Starting class file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF /classes/com/vo/bbs/AbstractBbs.class
    [instrument] class [com.vo.bbs.AbstractBbs] already instrumented
    [instrument] skipping file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF /classes/com/vo/bbs/AbstractBbs.class
    [instrument] Starting class file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF /classes/com/vo/bbs/Bbs.class
    [instrument] class [com.vo.bbs.Bbs] already instrumented
    [instrument] skipping file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF/classes/com/vo/bbs/Bbs.class
    [instrument] Starting class file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF /classes/com/vo/bbs/BbsDAO.class
    [instrument] class [com.vo.bbs.BbsDAO] already instrumented
    [instrument] skipping file : file:/E:/学习/我的java实验/MyEclipse7WS/network2009back/WebRoot/WEB-INF/classes/com/vo/bbs/BbsDAO.class
    BUILD SUCCESSFUL
    Total time: 1 second

    But when I tested the hibernate query “from VO”,”show_sql” showed that the lazy property “content” was still be selected.
    I really don’t know why this happened.Can somebody help me?

    #297257 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Post subject: Problems of Using lazy property fetching

You must be logged in to post in the forum log in