You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Paul Benedict <pb...@apache.org> on 2007/01/24 03:01:46 UTC

Re: Odd behavior with CGLIB (lazy loading problem)

Clinton,

I have a working example that I can email to you if you're interested. 
Can I email it? Here's a clearer explanation of what Niels and I are 
experiencing:

I have two classes: A which holds an instance of B. I have enhanced lazy 
loading turned on and I query for A with B being lazily loaded. The 
inner callback object which proxies B has a "loaded" boolean property (I 
mistakenly called this "initialized" in the previous email) which 
indicates whether the inner object has been truly loaded or needs to 
execute the query.

If B calls any internal methods in the constructor, which may be 
expected due to data initialization, then "loaded" is immediately marked 
as "true" and the query never executes.

Paul

Niels Beekman wrote:
> We had exactly the same issue, calling a method from within the
> constructor triggers "lazy" loading, which obviously isn't very lazy
> anymore.
>
> We ended up adding enhancer.setInterceptDuringConstruction(false) where
> an Enhancer-object is constructed (2 times in EnhancedLazyResultLoader).
>
> This could however cause problems when you are accessing uninitialized
> variables (not loaded from DB), but we're fine with that.
>
> HTH,
>
> Niels
>
> -----Original Message-----
> From: Paul Benedict [mailto:paulus.benedictus@gmail.com] On Behalf Of
> Paul Benedict
> Sent: dinsdag 23 januari 2007 5:05
> To: User Ibatis
> Subject: Odd behavior with CGLIB
>
> Can someone tell me if this is a bug in iBATIS:
>
> I turned on lazy loading of a class. In the constructor of the object, I
>
> called a protected method to initialize some properties. Example:
>
> public MyClassConstructor() {
>    setId(-1);
> }
>
> Because I called a method, iBATIS marked this class has "loaded" but it 
> was never really loaded. Only by replacing setId(-1) with this.id = -1; 
> was I able to prevent the "loaded" variable from being immediately set.
>
> I believe there is some sort of sequencing error here. The class should 
> not be considered initialized until after the constructor returns.
> Thoughts?
>
> Paul
>
>   


Re: Odd behavior with CGLIB (lazy loading problem)

Posted by Larry Meadors <lm...@apache.org>.
Why would you call the setter on a field defined in the class?

Larry


On 1/23/07, Paul Benedict <pb...@apache.org> wrote:
> Clinton,
>
> I have a working example that I can email to you if you're interested.
> Can I email it? Here's a clearer explanation of what Niels and I are
> experiencing:
>
> I have two classes: A which holds an instance of B. I have enhanced lazy
> loading turned on and I query for A with B being lazily loaded. The
> inner callback object which proxies B has a "loaded" boolean property (I
> mistakenly called this "initialized" in the previous email) which
> indicates whether the inner object has been truly loaded or needs to
> execute the query.
>
> If B calls any internal methods in the constructor, which may be
> expected due to data initialization, then "loaded" is immediately marked
> as "true" and the query never executes.
>
> Paul
>
> Niels Beekman wrote:
> > We had exactly the same issue, calling a method from within the
> > constructor triggers "lazy" loading, which obviously isn't very lazy
> > anymore.
> >
> > We ended up adding enhancer.setInterceptDuringConstruction(false) where
> > an Enhancer-object is constructed (2 times in EnhancedLazyResultLoader).
> >
> > This could however cause problems when you are accessing uninitialized
> > variables (not loaded from DB), but we're fine with that.
> >
> > HTH,
> >
> > Niels
> >
> > -----Original Message-----
> > From: Paul Benedict [mailto:paulus.benedictus@gmail.com] On Behalf Of
> > Paul Benedict
> > Sent: dinsdag 23 januari 2007 5:05
> > To: User Ibatis
> > Subject: Odd behavior with CGLIB
> >
> > Can someone tell me if this is a bug in iBATIS:
> >
> > I turned on lazy loading of a class. In the constructor of the object, I
> >
> > called a protected method to initialize some properties. Example:
> >
> > public MyClassConstructor() {
> >    setId(-1);
> > }
> >
> > Because I called a method, iBATIS marked this class has "loaded" but it
> > was never really loaded. Only by replacing setId(-1) with this.id = -1;
> > was I able to prevent the "loaded" variable from being immediately set.
> >
> > I believe there is some sort of sequencing error here. The class should
> > not be considered initialized until after the constructor returns.
> > Thoughts?
> >
> > Paul
> >
> >
>
>