-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Problems of Using lazy property fetching
PostPosted: Fri Apr 03, 2009 4:38 am 
Newbie

Joined: Fri Apr 03, 2009 4:15 am
Posts: 5
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:

Code:
<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:

Code:
<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:
Code:
<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:
Code:
<?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:
Code:
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?


Last edited by table686 on Sat Apr 04, 2009 2:29 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 9:29 am 
Newbie

Joined: Fri Apr 03, 2009 4:15 am
Posts: 5
can anybody help?please


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 8:06 pm 
Newbie

Joined: Fri Apr 03, 2009 4:15 am
Posts: 5
waiting


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 05, 2009 1:17 am 
Newbie

Joined: Fri Apr 03, 2009 4:15 am
Posts: 5
still waiting


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 05, 2009 4:48 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I have absolutely no experience with lazy loading so what I am going to write now is just a guess.

It seems like the documentation is outdated and I guess this has to do with the introduction of Javassist as the new byte-code generating library not so long ago. In addition to org.hibernate.tool.instrument.cglib.InstrumentTask there is also a org.hibernate.tool.instrument.javassist.InstrumentTask.

My guess is that you have to choose the same byte-code generation library for instrumentation as you later use with Hibernate. And I think the default library is now Javassist. But this can be changed as described in this thread: http://forum.hibernate.org/viewtopic.php?t=990648


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 11:14 am 
Newbie

Joined: Fri Apr 03, 2009 4:15 am
Posts: 5
nordborg wrote:
I have absolutely no experience with lazy loading so what I am going to write now is just a guess.

It seems like the documentation is outdated and I guess this has to do with the introduction of Javassist as the new byte-code generating library not so long ago. In addition to org.hibernate.tool.instrument.cglib.InstrumentTask there is also a org.hibernate.tool.instrument.javassist.InstrumentTask.

My guess is that you have to choose the same byte-code generation library for instrumentation as you later use with Hibernate. And I think the default library is now Javassist. But this can be changed as described in this thread: http://forum.hibernate.org/viewtopic.php?t=990648

Thanks a lot.I have tried the javassist class,but it did't work either.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.