使用例:

@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设定有效。

最新文章

  1. 检索Google Maps地图位置(小训练)
  2. PHP 判断点是否在多边形内
  3. 《Storm入门》中文版
  4. Winform DataGridView控件添加行号
  5. stl的仿函数adapter
  6. React Native教程 - 调用Web API
  7. The content of element type "sqlMapConfig" is incomplete,
  8. Android自定义带标题边框的Layout
  9. Python之路【第二篇】:Python基础
  10. 诗人般的机器学习,ML工作原理大揭秘
  11. placeholder是H5的一个新属性,但是在IE9以下是不支持的
  12. linux启动流程的理解
  13. input type=date时,时间数据回填,报错The specified value "2019-0404-18" does not conform to the required format, "yyyy-MM-dd".
  14. SVN快速入门笔记【转】
  15. less的写法 calc以及变量
  16. NAS (Network Attached Storage)
  17. 第三次spring会议
  18. (大数)Computer Transformation hdu1041
  19. codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
  20. Laravel-初体验笔记

热门文章

  1. 开发一个 Windows 级别的操作系统难度有多大?
  2. vue+vuex+axios从后台获取数据存入vuex,组件之间共享数据
  3. JAVA基于权重的抽奖
  4. laravel数据迁移
  5. Android Studio 连接 逍遥模拟器
  6. 简单封装axios api
  7. Laravel trait的使用
  8. Go按照条件编译
  9. PAT 1074. Reversing Linked List
  10. sql中,In和where的区别