FetchType.LAZY和Left Join Fetch的提取性能是否有所不同

时间:2019-05-19 10:57:44

标签: java hibernate jpa

我是Hibernate和JPA的新朋友。现在,我对FetchType.EAGER和Left Join Fetch之间的运行性能感到好奇。

例如。

  1. 选项1
@Entity
@Table(name = "EMPLOYEE")
public class Employee {

    @OneToMany(mappedBy = "employee", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private Set<Email> emails;
}
em.find(Employee.class, id)

休眠查询,例如:

select
   ...
from
    EMPLOYEE employee0_
left outer join
    Email email1_
        on employee0_.employee_id=email1_.employee_id
where
    employee0_.employee_id=?
  1. 选项2 如果我将员工电子邮件的注释从渴望更改为懒惰
@Entity
@Table(name = "EMPLOYEE")
public class Employee {

    @OneToMany(mappedBy = "employee", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<Email> emails;
}

em.createQuery ("select e from Employee e left join fetch e.emails ee where e.id=:id", Employee.class);

休眠查询,例如:

select
   ...
from
    EMPLOYEE employee0_
left outer join
    Email email1_
        on employee0_.employee_id=email1_.employee_id
where
    employee0_.employee_id=?

所以,我的问题是,由于SQL相同,因此以上两个是否等同于运行性能的观点。

非常感谢。

0 个答案:

没有答案