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 Daryl Stultz <da...@6degrees.com> on 2010/02/05 02:10:51 UTC

Monitoring lazy loading

Hello,

Getting a feeling for things, consider this code:

System.out.println("A");
um = session.getMapper(UserMapper.class);
user = um.findById(user.getId());
System.out.println("B");
session.close();
System.out.println("C");
assertEquals("Fred", user.getName());
System.out.println("D");
assertNotNull(user.getUserType()); // lazy loading
System.out.println("E");
assertEquals("doctor", user.getUserType().getName());
System.out.println("F");
assertEquals(ut.getId(), user.getUserType().getId());

user.userType is a lazy-loaded association. User.setUserType(ut) prints to
the console the name of the class of ut. The idea was to test if/when iBatis
calls setUserType and what it passes in. The above produces this output:

A
B
C
setUserType : model.UserType$EnhancerByCGLIB$49849362
setUserType : model.UserType$EnhancerByCGLIB$49849362
D
E
F

So this line of code:
assertEquals("Fred", user.getName());
appears to produce 2 calls to setUserType(). I did not expect any here. I
guess I thought the line before "B", the instantiation of user would cause a
proxy object to be set on userType. Can anyone shed some light on this?
Ultimately I'm trying to determine how I might track access and changes to
properties.

Thanks.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com

Re: Monitoring lazy loading

Posted by Daryl Stultz <da...@6degrees.com>.
On Thu, Feb 4, 2010 at 8:10 PM, Daryl Stultz <da...@6degrees.com> wrote:

> Hello,
>
> Getting a feeling for things, consider this code:
>

Well, after monkey'ing with the xml files, the print statements now appear
where expected. Unless there is something obvious here, please disregard.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com