-->
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.  [ 3 posts ] 
Author Message
 Post subject: Trying to generate classes that allow lazy property loading
PostPosted: Thu Feb 02, 2006 2:44 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
I'm trying to generate classes with cglib that allow lazy loading. I am doing this because I need to generate classes at runtime that deal with our content tables, and our content items can have very large image and text data associated with them.

As such, it would be a big performance win to not load the associated text or image data when loading the item's metadata.

I took the implementation from the InstrumentTask and I've tried to attach that to cglib when generating my runtime property classes. The problem is that lazy loading doesn't work properly. The lazy properties are not loaded (good) but don't load on access (bad).

Hibernate does seem to believe I've done the right thing. Unfortunately cglib is not well documented - the javadoc is largely devoid of class or method descriptions - which makes this rather hard to debug.

Here's how I attach the transform. I create the filter:

Code:
   public static class HibInterceptFieldFilter implements InterceptFieldFilter
   {
      public boolean acceptRead(Type owner, String name)
      {
         return true;
      }

      public boolean acceptWrite(Type owner, String name)
      {
         return true;
      }

      public boolean acceptRead(net.sf.cglib.asm.Type arg0, String arg1)
      {
         return true;
      }

      public boolean acceptWrite(net.sf.cglib.asm.Type arg0, String arg1)
      {
         return true;
      }
   };
   
   static InterceptFieldTransformer ms_xform =
      new InterceptFieldTransformer(new HibInterceptFieldFilter());

Then I use the filter when creating the class:
Code:
      gen.setStrategy(new DefaultGeneratorStrategy() {
         protected ClassGenerator transform(ClassGenerator cg) {
            return new TransformingClassGenerator(cg, ms_xform);
          }
        });

      Class beanClass = (Class) gen.createClass();


A last, possibly important, detail. I can't call the accessors on the generated class directly, so I'm going through reflection. Does this have any affect on Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 5:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Afraid I can't help with your cglib issues, but I have a Hibernate alternative that will work if you can't get cglib to do what you want. Define a class for each column that you want to defer loading on, and remove the column from your exisitng class definitions. Add a one-to-one lazy="true" fetch="select" mapping from the existing classes to the various new classes. Obviously you'll end up with an extra method call (contentObject.getImageObject().getImageData(), or whatever), but it guarantees that hibernate will never eagerly load the blobs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 5:26 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I see no good way to implement it in user code, hibernate uses "if(object instanceof InterfeptFieldEnabled )" and you will break it.

Register issue in JIRA to fix lazy property loading in hibernate, if it doe's not work, it is core hibernate code functionality.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.