ibatis 2.3.x可以延迟加载java.lang.Integer吗?

时间:2018-09-14 13:25:22

标签: java sql orm lazy-loading ibatis

试图延迟加载java.land.Integer。延迟加载属性:

<result property="foo.cnt" column="id" select="getCnt"/>

Sql语句是这样完成的:

<sql id="sql-getCnt">
    SELECT count(*) as cnt
    FROM  bar b INNER JOIN bar2 b2 on b.id = b2.id
    WHERE bar.id=#id#
    AND b2.workds IS NULL
</sql>

选择语句是这样完成的:

<select id="getCnt" parameterClass="int" resultClass="java.lang.Integer">
    <include refid="sql-getCnt"/>
</select>

设置:

<settings 
    enhancementEnabled="true"
    errorTracingEnabled="true"
    lazyLoadingEnabled="true"
    useStatementNamespaces="true"
/>

我希望延迟加载有效。但这就是我在日志中看到的: Select count statement goes right after first select statement - this means that lazy loading doesn't work. To ensure nothing reads object fields I force thread sleep for one minute right after querying the object.

如何完成Integer的延迟加载?可以做到吗?

1 个答案:

答案 0 :(得分:0)

原因是java.lang.Integer类是最终类,因此cglib无法为其创建代理对象。答案很简单。