ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daryl Stultz <da...@6degrees.com>
Subject Expected lazy loading, got eager.
Date Sat, 06 Feb 2010 20:37:30 GMT
Hello,

I've got a mapper like this:

<mapper namespace="model.UserMapper">

<resultMap id="userResult" type="User">
<id property="id" column="user_id" />
<result property="name" column="user_name" />
<association property="userType" column="user_usertypeid"
javaType="UserType" select="model.UserTypeMapper.findById" />
 </resultMap>
 <select id="findById" parameterType="Integer" resultMap="userResult">
select userId as user_id, name as user_name, userTypeId as user_userTypeId
from Users
where userId = #{id}
</select>
</mapper>

and another like this:

<mapper namespace="model.UserTypeMapper">

<select id="findById" parameterType="Integer" resultType="UserType">
select userTypeId as id, name
from UserTypes
where userTypeId = #{id}
</select>
</mapper>

So User has a many-to-one association with UserType. When I run this:

user = userMapper.findById(123);

these 2 queries are executed:

select userId as user_id, name as user_name, userTypeId as user_userTypeId
from Users where userId = ?
select userTypeId as id, name from UserTypes where userTypeId = ?

So it looks like user.userType is being eagerly loaded. How do I set things
up to be lazy loaded? I have <setting name="lazyLoadingEnabled" value="true"
/> even though the default is true. I have confirmed that my classes are
being enhanced by CGLIB.

Thanks for the help.

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

Mime
View raw message