xsunil kumar wrote:Nitin,
..............................
...............................
Employee employee=(Employee)q.getSingleResult();
// write code block to fetch LeaveApprovalHierarchy object.
Set <LeaveApprovalHierarchy> sL1=emp.getLeaveHierarchy();
Iterator<LeaveApprovalHierarchy> i1=sL1.iterator();
................................
................................
above is only sample to do this. You need to rectify above code.
Sunil
xsunil kumar wrote:
For avoiding this exception, you need to force hibernate to load LeaveApprovalHierarchy object also along with employee. As hibernate will do this on demand and session should be open. The way to do is after getting employee object , get LeaveApprovalHierarchy by employee.<get method of LeaveApprovalHierarchy object> and access these values of LeaveApprovalHierarchy object. So what will happen, up to this instance your session is not closed and you are trying to fetch LeaveApprovalHierarchy object from employee object so it will create ondemand rule and hiberante will load this entity also.
After that you can close your hibernate session.
Employee employee=(Employee)q.getSingleResult();
// write code block to fetch LeaveApprovalHierarchy object.
Set <LeaveApprovalHierarchy> sL1=employee.getLeaveHierarchy(); /// Here you are using employee which is returned by hibernate session.
Iterator<LeaveApprovalHierarchy> i1=sL1.iterator(); //creating on demand request.
session.close(); // closing hibernate session.
Sunil
Wanna see my flashlight? How about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|