lazy loading issues

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

lazy loading issues

Raj Nagappan
Hi all, I am having an issue with lazy loading where it fetches the
lazy loaded object too eagerly. I can post some code for this a little
later, but in the meantime...

Say I have two objects A and B, where B is a lazy loaded property of A
and is fetched using a select clause in A's result map. I'm also using
cglib-nodep 2.2 as B is a POJO and not an interface. A has other
properties like id and name. The problem is that calling A.getId() or
A.getName() triggers a lazy load on B, even though I haven't touched
A.getB() or A.B or anything like that.

Any ideas? This is occurring in my Spring-Mybatis integration tests,
but I suspect it has nothing to do with Spring but rather is a Mybatis
core issue.
Reply | Threaded
Open this post in threaded view
|

RE: lazy loading issues

Poitras Christian
The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.

Christian

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Raj Nagappan
Sent: Sunday, August 29, 2010 8:21 PM
To: mybatis-user
Subject: lazy loading issues

Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...

Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
A.getName() triggers a lazy load on B, even though I haven't touched
A.getB() or A.B or anything like that.

Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.
Reply | Threaded
Open this post in threaded view
|

Re: lazy loading issues

Clinton Begin
Administrator
I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.

Clinton

On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]> wrote:
The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.

Christian

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Raj Nagappan
Sent: Sunday, August 29, 2010 8:21 PM
To: mybatis-user
Subject: lazy loading issues

Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...

Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
A.getName() triggers a lazy load on B, even though I haven't touched
A.getB() or A.B or anything like that.

Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.

Reply | Threaded
Open this post in threaded view
|

RE: lazy loading issues

Poitras Christian
It's not in downloadable PDF yet. It needs to be updated.
 
Christian


From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
Sent: Monday, August 30, 2010 11:06 AM
To: [hidden email]
Subject: Re: lazy loading issues

I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.

Clinton

On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]> wrote:
The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.

Christian

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Raj Nagappan
Sent: Sunday, August 29, 2010 8:21 PM
To: mybatis-user
Subject: lazy loading issues

Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...

Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
A.getName() triggers a lazy load on B, even though I haven't touched
A.getB() or A.B or anything like that.

Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.

Reply | Threaded
Open this post in threaded view
|

Re: lazy loading issues

Raj Nagappan
Ok thanks. All our existing code in A calls getB() whenever we need a
reference to it, so it's safe (and desirable) for us to delay lazy
loading as long as possible. Since NONE, AGGRESSIVE, PARTIAL are not
documented yet, what is the difference between them?

Raj.

On Aug 31, 1:30 am, Poitras Christian <[hidden email]>
wrote:

> It's not in downloadable PDF yet. It needs to be updated.
>
> Christian
>
> ________________________________
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
> Sent: Monday, August 30, 2010 11:06 AM
> To: [hidden email]
> Subject: Re: lazy loading issues
>
> I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.
>
> Clinton
>
> On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]<mailto:[hidden email]>> wrote:
> The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
> You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.
>
> Christian
>
> -----Original Message-----
> From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Raj Nagappan
> Sent: Sunday, August 29, 2010 8:21 PM
> To: mybatis-user
> Subject: lazy loading issues
>
> Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...
>
> Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
> A.getName() triggers a lazy load on B, even though I haven't touched
> A.getB() or A.B or anything like that.
>
> Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.
Reply | Threaded
Open this post in threaded view
|

Re: lazy loading issues

Raj Nagappan
In reply to this post by Poitras Christian
Ok thanks. All our existing code in A calls getB() whenever we need a
reference to it, so it's safe (and desirable) for us to delay lazy
loading as long as possible. Since NONE, AGGRESSIVE, PARTIAL are not
documented yet, what is the difference between them?

Raj.

On Aug 31, 1:30 am, Poitras Christian <[hidden email]>
wrote:

> It's not in downloadable PDF yet. It needs to be updated.
>
> Christian
>
> ________________________________
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
> Sent: Monday, August 30, 2010 11:06 AM
> To: [hidden email]
> Subject: Re: lazy loading issues
>
> I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.
>
> Clinton
>
> On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]<mailto:[hidden email]>> wrote:
> The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
> You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.
>
> Christian
>
> -----Original Message-----
> From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Raj Nagappan
> Sent: Sunday, August 29, 2010 8:21 PM
> To: mybatis-user
> Subject: lazy loading issues
>
> Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...
>
> Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
> A.getName() triggers a lazy load on B, even though I haven't touched
> A.getB() or A.B or anything like that.
>
> Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.
Reply | Threaded
Open this post in threaded view
|

Re: lazy loading issues

Clinton Begin
Administrator
Sorry, ignore me... I was thinking of the auto-mapping.  It has NONE, FULL and PARTIAL.....

The lazyloading is still as Christian described it.   I'll try not to respond from memory from now on.  LOL  :-)

Clinton

On Mon, Aug 30, 2010 at 5:06 PM, Raj Nagappan <[hidden email]> wrote:
Ok thanks. All our existing code in A calls getB() whenever we need a
reference to it, so it's safe (and desirable) for us to delay lazy
loading as long as possible. Since NONE, AGGRESSIVE, PARTIAL are not
documented yet, what is the difference between them?

Raj.

On Aug 31, 1:30 am, Poitras Christian <[hidden email]>
wrote:
> It's not in downloadable PDF yet. It needs to be updated.
>
> Christian
>
> ________________________________
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
> Sent: Monday, August 30, 2010 11:06 AM
> To: [hidden email]
> Subject: Re: lazy loading issues
>
> I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.
>
> Clinton
>
> On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]<mailto:[hidden email]>> wrote:
> The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
> You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.
>
> Christian
>
> -----Original Message-----
> From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Raj Nagappan
> Sent: Sunday, August 29, 2010 8:21 PM
> To: mybatis-user
> Subject: lazy loading issues
>
> Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...
>
> Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
> A.getName() triggers a lazy load on B, even though I haven't touched
> A.getB() or A.B or anything like that.
>
> Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.

Reply | Threaded
Open this post in threaded view
|

RE : lazy loading issues

Poitras Christian
In reply to this post by Raj Nagappan
You can try, but I am not sure that a call to this.getB() inside a method in A will be intercepted and call the select. In such cases I think you'll end up with an NPE. Try out!

As for what NONE, AGRESSIVE and PARTIAL means.
NONE: I don't know. You should ask Clinton.
AGRESSIVE - the default: Load all properties of A as soon as a method of A is called. Prevent all NPE but will increase the load. I think this must be kept for POJOs since they don't have getters.
PARTIAL: Load a property only when it's getter is intercepted.

Christian

________________________________________
De : [hidden email] [[hidden email]] de la part de Raj Nagappan [[hidden email]]
Date d'envoi : lundi 30 août 2010 19:05
À : mybatis-user
Objet : Re: lazy loading issues

Ok thanks. All our existing code in A calls getB() whenever we need a
reference to it, so it's safe (and desirable) for us to delay lazy
loading as long as possible. Since NONE, AGGRESSIVE, PARTIAL are not
documented yet, what is the difference between them?

Raj.

On Aug 31, 1:30 am, Poitras Christian <[hidden email]>
wrote:

> It's not in downloadable PDF yet. It needs to be updated.
>
> Christian
>
> ________________________________
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
> Sent: Monday, August 30, 2010 11:06 AM
> To: [hidden email]
> Subject: Re: lazy loading issues
>
> I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.
>
> Clinton
>
> On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]<mailto:[hidden email]>> wrote:
> The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
> You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.
>
> Christian
>
> -----Original Message-----
> From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Raj Nagappan
> Sent: Sunday, August 29, 2010 8:21 PM
> To: mybatis-user
> Subject: lazy loading issues
>
> Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...
>
> Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
> A.getName() triggers a lazy load on B, even though I haven't touched
> A.getB() or A.B or anything like that.
>
> Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.
Reply | Threaded
Open this post in threaded view
|

Re: RE : lazy loading issues

Raj Nagappan
Tried it true/false settings and it worked no problem (in Mybatis
3.0.1). I also tested the call to getB() from within a method in A and
it lazy loaded correctly. This second part always worked in iBatis 2.3
so I see reason why that would have changed.

Thanks guys.

On Aug 31, 10:18 pm, Poitras Christian <[hidden email]>
wrote:

> You can try, but I am not sure that a call to this.getB() inside a method in A will be intercepted and call the select. In such cases I think you'll end up with an NPE. Try out!
>
> As for what NONE, AGRESSIVE and PARTIAL means.
> NONE: I don't know. You should ask Clinton.
> AGRESSIVE - the default: Load all properties of A as soon as a method of A is called. Prevent all NPE but will increase the load. I think this must be kept for POJOs since they don't have getters.
> PARTIAL: Load a property only when it's getter is intercepted.
>
> Christian
>
> ________________________________________
> De : [hidden email] [[hidden email]] de la part de Raj Nagappan [[hidden email]]
> Date d'envoi : lundi 30 août 2010 19:05
> À : mybatis-user
> Objet : Re: lazy loading issues
>
> Ok thanks. All our existing code in A calls getB() whenever we need a
> reference to it, so it's safe (and desirable) for us to delay lazy
> loading as long as possible. Since NONE, AGGRESSIVE, PARTIAL are not
> documented yet, what is the difference between them?
>
> Raj.
>
> On Aug 31, 1:30 am, Poitras Christian <[hidden email]>
> wrote:
>
> > It's not in downloadable PDF yet. It needs to be updated.
>
> > Christian
>
> > ________________________________
> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Clinton Begin
> > Sent: Monday, August 30, 2010 11:06 AM
> > To: [hidden email]
> > Subject: Re: lazy loading issues
>
> > I think we switched it from a boolean to values like NONE, AGGRESSIVE, PARTIAL or something like that.  Pretty sure it's in the docs, let us know if you can't find it.
>
> > Clinton
>
> > On Mon, Aug 30, 2010 at 8:33 AM, Poitras Christian <[hidden email]<mailto:[hidden email]>> wrote:
> > The reason it happens this way is because some methods in A may want to use B. If B is not loaded before the call to A, then there would be a problem (B would be null throwing an NPE).
> > You can change the behaviour by changing the attribute "aggressiveLazyLoading" to false.
>
> > Christian
>
> > -----Original Message-----
> > From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Raj Nagappan
> > Sent: Sunday, August 29, 2010 8:21 PM
> > To: mybatis-user
> > Subject: lazy loading issues
>
> > Hi all, I am having an issue with lazy loading where it fetches the lazy loaded object too eagerly. I can post some code for this a little later, but in the meantime...
>
> > Say I have two objects A and B, where B is a lazy loaded property of A and is fetched using a select clause in A's result map. I'm also using cglib-nodep 2.2 as B is a POJO and not an interface. A has other properties like id and name. The problem is that calling A.getId() or
> > A.getName() triggers a lazy load on B, even though I haven't touched
> > A.getB() or A.B or anything like that.
>
> > Any ideas? This is occurring in my Spring-Mybatis integration tests, but I suspect it has nothing to do with Spring but rather is a Mybatis core issue.