I am a new person for Hibernate & JPA. Now, I am curious about the running performance between FetchType.EAGER and Left Join Fetch.
For example.
- Option 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)
the hibernate query like:
select
...
from
EMPLOYEE employee0_
left outer join
Email email1_
on employee0_.employee_id=email1_.employee_id
where
employee0_.employee_id=?
- Option 2 if I change the annotation of email on employee from eager into lazy
@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);
the hibernate query like:
select
...
from
EMPLOYEE employee0_
left outer join
Email email1_
on employee0_.employee_id=email1_.employee_id
where
employee0_.employee_id=?
So, my question is that does the above two is equal to the running performance perspective because the SQL is the same.
Many thanks.