FetchType与FetchMode的区别
使用例:
@OneToMany(mappedBy="item",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@Fetch(value=FetchMode.SUBSELECT)
两者比较:
两者都是设定关联对象的加载策略。前者是JPA标准的通用加载策略注解属性,
后者是Hibernate自有加载策略注解属性。
FetchType可选值意义与区别如下:
FetchType.LAZY: 懒加载,在访问关联对象的时候加载(即从数据库读入内存)
FetchType.EAGER:立刻加载,在查询主对象的时候同时加载关联对象。
FetchMode可选值意义与区别如下:
@ Fetch (FetchMode.JOIN) will use the left join query produced only one sql statement
@ Fetch (FetchMode.SELECT) will have N +1 clause sql statement
@ Fetch (FetchMode.SUBSELECT) produce two sql statement to use the second statement id in (.....) check out all the data associated
@Fetch(FetchMode.JOIN): 始终立刻加载,使用外连(outer join)查询的同时加载关联对象,忽略FetchType.LAZY设定。
@Fetch(FetchMode.SELECT) :默认懒加载(除非设定关联属性lazy=false),当访问每一个关联对象时加载该对象,会累计产生N+1条sql语句
@Fetch(FetchMode.SUBSELECT) 默认懒加载(除非设定关联属性lazy=false),在访问第一个关联对象时加载所有的关联对象。会累计产生两条sql语句。且FetchType设定有效。
最新文章
- 检索Google Maps地图位置(小训练)
- PHP 判断点是否在多边形内
- 《Storm入门》中文版
- Winform DataGridView控件添加行号
- stl的仿函数adapter
- React Native教程 - 调用Web API
- The content of element type ";sqlMapConfig"; is incomplete,
- Android自定义带标题边框的Layout
- Python之路【第二篇】:Python基础
- 诗人般的机器学习,ML工作原理大揭秘
- placeholder是H5的一个新属性,但是在IE9以下是不支持的
- linux启动流程的理解
- input type=date时,时间数据回填,报错The specified value ";2019-0404-18"; does not conform to the required format, ";yyyy-MM-dd";.
- SVN快速入门笔记【转】
- less的写法 calc以及变量
- NAS (Network Attached Storage)
- 第三次spring会议
- (大数)Computer Transformation hdu1041
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
- Laravel-初体验笔记