在学习MyBatis懒加载时遇到的一个小问题,新手求解。

yolre 2019-11-21 04:38:56
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[DEBUG] ==> Preparing: SELECT cid,cname FROM country WHERE cid=?
[DEBUG] ==> Parameters: 1(Integer)
[DEBUG] ====> Preparing: SELECT mid,mname from minister where countryId=?
[DEBUG] ====> Parameters: 1(Integer)
[DEBUG] <==== Total: 3
[DEBUG] <== Total: 1
USA

Process finished with exit code 0

还未使用懒加载时,正常情况下如上述所示,这个是正常现象。
当我在mybtais的xml配置文件中settings标签加入<setting name="lazyLoadingEnabled" value="true"/>运行时
Run状态下:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[DEBUG] ==> Preparing: SELECT cid,cname FROM country WHERE cid=?
[DEBUG] ==> Parameters: 1(Integer)
[DEBUG] <== Total: 1
USA

Process finished with exit code 0

但是在Debug状态下确是这样:
第一次Debug运行结果:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[DEBUG] ==> Preparing: SELECT cid,cname FROM country WHERE cid=?
[DEBUG] ==> Parameters: 1(Integer)
[DEBUG] <== Total: 1
[DEBUG] ==> Preparing: SELECT mid,mname from minister where countryId=?
[DEBUG] ==> Parameters: 1(Integer)
[DEBUG] <== Total: 3

第二次Debug运行结果:
USA



这里我好奇的是,当我使用lazyLoadingEnabled为true打开延迟加载时,不应该只出现第一条查询country的sql语句吗,为什么minister的sql语句会跟着一起出现?是我的问题还是idea的工具特性?
希望有大佬能解决小白的疑惑。
...全文
110 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yolre 2019-11-21
  • 打赏
  • 举报
回复
我将项目从idea迁移至myclipse中Debug发现,代码并没有任何问题,输出结果跟我预期的一样。证明是idea的问题了,有谁知道吗?

50,526

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧