zoukankan      html  css  js  c++  java
  • 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设定有效。

  • 相关阅读:
    版本控制器 git
    JS 严格模式
    backquote
    linux内存监控 free
    好的linux网站
    linux查看进程开始时间
    命令之 ulimit
    using JSTL
    javax.servlet.jsp.PageContext cannot be resolved to a type
    jstl c
  • 原文地址:https://www.cnblogs.com/fashflying/p/5147473.html
Copyright © 2011-2022 走看看