我是Hibernate和JPA的新朋友。现在,我对FetchType.EAGER和Left Join Fetch之间的运行性能感到好奇。
例如。
@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=?
@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相同,因此以上两个是否等同于运行性能的观点。
非常感谢。