hibernate 小记
来源:互联网 发布:电脑测试网络运行 编辑:程序博客网 时间:2024/05/19 17:02
当使用 jion fetch 时,查询出多条重复记录,这是因为多表连续查询的结果
可以加关键词DISTINCT查出唯一值(不过用这个性能会慢些)
例子
"select cl from CheckList cl" +" left join fetch cl.checkCell cc" +" left join fetch cl.assets a" +" left join fetch a.currentCycle c"+" left join fetch c.location l"+" left join fetch a.origin o"+" left join fetch a.app app"+" left join fetch c.cycleState cs"+" left join fetch c.department dp"+" left join fetch dp.mainNode dpm"+" left join fetch c.assetsState ats"+" left join fetch a.expands ed"+" left join fetch ed.value vl"+" left join fetch vl.field fd"+" left join fetch a.contract cont"+" left join fetch a.parts p"+" left join fetch p.expands ped"+" left join fetch ped.value pvl"+" left join fetch pvl.field pfd"+" where cc.id in (:ids)";
这里多表链接,如果其它表有多条记录对于,查出的列表就可能包含多条重复的记录
"select DISTINCT cl from CheckList cl" +" left join fetch cl.checkCell cc" +" left join fetch cl.assets a" +" left join fetch a.currentCycle c" +" left join fetch c.location l" +" left join fetch a.origin o" +" left join fetch a.app app" +" left join fetch c.cycleState cs" +" left join fetch c.department dp" +" left join fetch dp.mainNode dpm" +" left join fetch c.assetsState ats" +" left join fetch a.expands ed" +" left join fetch ed.value vl" +" left join fetch vl.field fd" +" left join fetch a.contract cont" +" left join fetch a.parts p" +" left join fetch p.expands ped" +" left join fetch ped.value pvl" +" left join fetch pvl.field pfd" +" where cc.id in (:ids)";
这个加了DISTINCT ,就不会重复了
HQL查询的聚集函数
avg: 计算属性平均值
count:数量
max:统计对象最大值
min:统计对象最小值
sum:统计属性值综合
例:
select count(*) from Userselect max(u.age) from User as u
0 0
- hibernate小记
- hibernate 小记
- hibernate小记
- hibernate 小记
- Hibernate小记
- Hibernate学习小记
- hibernate+spring myeclipse小记
- Hibernate学习小记
- Hibernate 与 JPA 小记
- hibernate @mappedBy小记
- Hibernate使用小记
- hibernate学习小记
- 使用Hibernate 操作Clob成功小记
- Hibernate调用mysql5.0存储过程小记
- Hibernate调用mysql5.0存储过程小记
- Myeclipse开发struts+hibernate+spring小记
- hibernate 未明确定义列 小记
- hibernate中集合映射关联映射小记
- setAnimationStyle实现的popwindow显示消失的动画效果
- Git和Gitlab协同工作
- JSON和XML:不可同日而语
- appium+Python运行脚本环境
- Leetcode 136. Single Number
- hibernate 小记
- 如何在SQL中先排序后分组
- 解决python中路径中包含中文无法找到文件的问题
- Oracle基础
- 常用的正则表达式使用方法
- Oracle查询数据表数据很少却很慢(查询空表很很耗时)
- Java中输出当前时间的各种方法(较齐全)
- maven
- WSAAsyncSelect模型实例讲解