i having one-to-many relationship between employee , department , class looking :
@entity public class employee { @id private int empid; private string empname; @onetomany @jointable (name = "relationaltable" , joincolumns = @joincolumn(name = "empid"),inversejoincolumns=@joincolumn(name = "deptid")) private collection <department> dept = new arraylist<department>(); public int getempid() { return empid; } public void setempid(int empid) { this.empid = empid; } public collection<department> getdept() { return dept; } public void setdept(collection<department> dept) { this.dept = dept; } @column public string getempname() { return empname; } public void setempname(string empname) { this.empname = empname; } }
and department class :
@entity public class department { int deptid; string deptname; private employee emp; @manytoone public employee getemp() { return emp; } public void setemp(employee emp) { this.emp = emp; } @id public int getdeptid() { return deptid; } public void setdeptid(int deptid) { this.deptid = deptid; } @column public string getdeptname() { return deptname; } public void setdeptname(string deptname) { this.deptname = deptname; } }
if fetch department. fetch employee @ same time associated it. department id 1 there 1000 employee. how many queries execute @ time database fetch data?
if fetchtype lazy hibernate retrieve record when try access departments
if eager hibernate join queries 1 queries , execute 1 query.
Comments
Post a Comment