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

问题描述 投票:2回答:1

试图懒惰加载java.lang.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?它可以完成吗?

java sql orm lazy-loading ibatis
1个回答
0
投票

原因是java.lang.Integer类是final的,因此cglib无法为它创建代理对象。答案很简单明了。

© www.soinside.com 2019 - 2024. All rights reserved.