Hibernate query executes more than expexcted times
I have the below mentioned Entity relationship. When I run my application,
I can see that the below query generated by Hibernate executes 13
times(1+12) where 12 is the number of rows I am displaying in front end
application. Ideally it should have executed only once as I am not sure
why it is getting executed 12 times. If I change my number of rows to be
displayed in front end application to say 20, then query executes 21
times.
How can I resolve this issue?
Hibernate auto generated query
select employee0_.EMPLOYEE_NUMBER as EMP1_2_0_, employee0_.DEPARTMENT_CODE as
DEPARTMENT3_2_0_, employee0_.EMPLOYEE_DEPT as EMPLOYEE4_2_0_,
employee0_.DESIGNATION
as DESIGNAT5_2_0_, employee0_.EMPLOYEE_NAME as EMPLOYEE6_2_0_ from EMPLOYEES
employee0_ where employee0_.EMPLOYEE_NUMBER=?
Entity Classes
@Entity
public class Project
@ManyToOne
@JoinColumn(name = "EMPLOYEE_NUMBER", referencedColumnName =
"EMPLOYEE_NUMBER")
private Employee requester;
@ManyToOne
@JoinColumn(name = "APPROVER", referencedColumnName = "EMPLOYEE_NUMBER")
private Employee approver;
}
@Entity
public class Employee {
@OneToMany(mappedBy = "requester")
private Set<Project> requestedProjects;
@OneToMany(mappedBy = "approver")
private Set<Project> approvedProjects;
}
No comments:
Post a Comment