1.查询缓存
在使用外连接进行查询时需要注意查询缓存的使用
hibernate的xml配置文件,当一对多中配置抓取策略为join时
<set inverse="true" access="field" name="childern" fetch="join" cascade="save-update,persist" >
<key column="PID"/>
<one-to-many class="com.going.platform.model.Organization"/>
</set>
String hsql=" from Organization porg left outer join fetch porg.childern as corg ";
List<Organization> results=super.getSession().createQuery(hsql).setCacheable(true).list();
进行查询时 第一次查询会使用外连接的方式来进行查询,查询的sql语句
select
this_.ID as ID0_1_,
this_.ORGANIZATION_NAME as ORGANIZA2_0_1_,
this_.ORGANIZATION_SN as ORGANIZA3_0_1_,
this_.DESCRIPTION as DESCRIPT4_0_1_,
this_.PID as PID0_1_,
this_.ORGANIZATION_TEL as ORGANIZA6_0_1_,
this_.ORDER_NUM as ORDER7_0_1_,
this_.PERSON_ID as PERSON8_0_1_,
childern2_.PID as PID3_,
childern2_.ID as ID3_,
childern2_.ID as ID0_0_,
childern2_.ORGANIZATION_NAME as ORGANIZA2_0_0_,
childern2_.ORGANIZATION_SN as ORGANIZA3_0_0_,
childern2_.DESCRIPTION as DESCRIPT4_0_0_,
childern2_.PID as PID0_0_,
childern2_.ORGANIZATION_TEL as ORGANIZA6_0_0_,
childern2_.ORDER_NUM as ORDER7_0_0_,
childern2_.PERSON_ID as PERSON8_0_0_
from
g_organization this_
left outer join
g_organization childern2_
on this_.ID=childern2_.PID
但配置了查询缓存 第二次点击时 则会产生如下sql语句
select
organizati0_.ID as ID0_1_,
organizati0_.ORGANIZATION_NAME as ORGANIZA2_0_1_,
organizati0_.ORGANIZATION_SN as ORGANIZA3_0_1_,
organizati0_.DESCRIPTION as DESCRIPT4_0_1_,
organizati0_.PID as PID0_1_,
organizati0_.ORGANIZATION_TEL as ORGANIZA6_0_1_,
organizati0_.ORDER_NUM as ORDER7_0_1_,
organizati0_.PERSON_ID as PERSON8_0_1_,
childern1_.PID as PID3_,
childern1_.ID as ID3_,
childern1_.ID as ID0_0_,
childern1_.ORGANIZATION_NAME as ORGANIZA2_0_0_,
childern1_.ORGANIZATION_SN as ORGANIZA3_0_0_,
childern1_.DESCRIPTION as DESCRIPT4_0_0_,
childern1_.PID as PID0_0_,
childern1_.ORGANIZATION_TEL as ORGANIZA6_0_0_,
childern1_.ORDER_NUM as ORDER7_0_0_,
childern1_.PERSON_ID as PERSON8_0_0_
from
g_organization organizati0_
left outer join
g_organization childern1_
on organizati0_.ID=childern1_.PID
where
organizati0_.ID=?
Hibernate:
select
organizati0_.ID as ID0_1_,
organizati0_.ORGANIZATION_NAME as ORGANIZA2_0_1_,
organizati0_.ORGANIZATION_SN as ORGANIZA3_0_1_,
organizati0_.DESCRIPTION as DESCRIPT4_0_1_,
organizati0_.PID as PID0_1_,
organizati0_.ORGANIZATION_TEL as ORGANIZA6_0_1_,
organizati0_.ORDER_NUM as ORDER7_0_1_,
organizati0_.PERSON_ID as PERSON8_0_1_,
childern1_.PID as PID3_,
childern1_.ID as ID3_,
childern1_.ID as ID0_0_,
childern1_.ORGANIZATION_NAME as ORGANIZA2_0_0_,
childern1_.ORGANIZATION_SN as ORGANIZA3_0_0_,
childern1_.DESCRIPTION as DESCRIPT4_0_0_,
childern1_.PID as PID0_0_,
childern1_.ORGANIZATION_TEL as ORGANIZA6_0_0_,
childern1_.ORDER_NUM as ORDER7_0_0_,
childern1_.PERSON_ID as PERSON8_0_0_
from
g_organization organizati0_
left outer join
g_organization childern1_
on organizati0_.ID=childern1_.PID
where
organizati0_.ID=?
个人认为是,hibernate中会得出拥有子节点的数据id、,然后根据Id进行外连接进行查询
但如果取消查询缓存的话 每次都会调用同一语句
select
this_.ID as ID0_1_,
this_.ORGANIZATION_NAME as ORGANIZA2_0_1_,
this_.ORGANIZATION_SN as ORGANIZA3_0_1_,
this_.DESCRIPTION as DESCRIPT4_0_1_,
this_.PID as PID0_1_,
this_.ORGANIZATION_TEL as ORGANIZA6_0_1_,
this_.ORDER_NUM as ORDER7_0_1_,
this_.PERSON_ID as PERSON8_0_1_,
childern2_.PID as PID3_,
childern2_.ID as ID3_,
childern2_.ID as ID0_0_,
childern2_.ORGANIZATION_NAME as ORGANIZA2_0_0_,
childern2_.ORGANIZATION_SN as ORGANIZA3_0_0_,
childern2_.DESCRIPTION as DESCRIPT4_0_0_,
childern2_.PID as PID0_0_,
childern2_.ORGANIZATION_TEL as ORGANIZA6_0_0_,
childern2_.ORDER_NUM as ORDER7_0_0_,
childern2_.PERSON_ID as PERSON8_0_0_
from
g_organization this_
left outer join
g_organization childern2_
on this_.ID=childern2_.PID
来进行查询。。。。
得出结论就是在使用外连接时,应该注意到并不是所有条件不会变化的sql语句,使用查询缓存的命中率就会高
查询缓存(一)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Java项目面试实操 提升大厂面试成功率
wy53780
2020-04-23 14:14:04
玩转算法系列--图论精讲 面试升职必备(Java版)
wy53780
2020-04-23 14:03:23
玩转Java并发工具,精通JUC,成为并发多面手
wy53780
2020-04-23 13:56:08
线程八大核心+Java并发底层原理精讲(Java并发核心知识体系精讲)
wy53780
2020-04-23 13:55:55
Java通用型支付+电商平台双系统实战
wy53780
2020-04-23 13:54:42
【跃迁之路】【734天】程序员高效学习方法论探索系列(实验阶段491-2019.2.24)
Wall_Breaker
2019-02-24 23:25:10
Java是怎么运行的?
勤思
2019-02-24 22:52:36
sql语法、关系建模
死瘦宅
2019-02-24 22:35:22
MySQL 事务、函数、触发器、数据库备份、权限管理
死瘦宅
2019-02-24 22:35:12
Python与家国天下
豌豆花下貓
2019-02-24 22:22:40
Java面试 | 002
Java貓說
2019-02-24 21:05:12
《从0到1学习Flink》—— Flink 读取 Kafka 数据批量写入到 MySQL
zhisheng
2019-02-24 21:04:11
Redis | 001能做什么?
Java貓說
2019-02-24 21:03:51
java中具有继承关系的类及其对象初始化顺序
Linus脫襪子
2019-02-24 19:55:05
24小時熱門文章
-
再谈23种设计模式(3):行为型模式(学习笔记)
-
Power Automate Desktop 安装完,登录后老是提示one driver 错误
-
微前端学习笔记(4):从微前端到微模块之EMP与hel-micro方案探索
-
微前端学习笔记(1):微前端总体架构概述,从微服务发微
-
985 硕士程序员,空窗 4 个月没有 Offer!
-
一文搞懂 Spring 循环依赖
-
赛博斗地主——使用大语言模型扮演Agent智能体玩牌类游戏。
-
VScode右键打开(添加到右键)
-
记一次 .NET某工控视觉自动化系统 卡死分析
-
WindowsServer--SQL Server搭建主从同步实现读写分离 - 事务性分发