-
1. Re: FetchType.Lazy
cyril.joui Jan 15, 2006 6:12 PM (in response to clarif)Hello !
You must explicitly initialize your object before returning it to your webapp !
You can do this just with calling the size() method of your collection !
Of course it would be easier if you use the Facade Pattern with a Session Bean !
for example (in the session bean)public Employee findEmployee(int id) { Employee employee = employeeDao.findEmployeeById(id); // this line initialize address collection // be careful if the collection == null !!! employee.getAddress().size(); }
I hope it would be easier for you ;)
Good luck -
2. Re: FetchType.Lazy
clarif Jan 16, 2006 10:29 AM (in response to clarif)Hi Cyril,
Many thanks for your answer.
One precision: do I need to do the same thing in case of a Collection? eg inside the session, I have Collection getAllEmployee(). I tried to make a loop on that collection and initialize the address for each employee but it does not work (but it worked for getEmployeeById()). Is is normal?
Once again, thanks for your help.
Regards,
Fabrice. -
3. Re: FetchType.Lazy
cyril.joui Jan 16, 2006 10:33 AM (in response to clarif)Hello,
By default, the OneTOne and OneToMany is loaded automaticaly.
Collections are automaticly in the lazy mode !
If you have a Collection of User and a User has a Collection of resources and a Resource has a collection of Category (for example).
You must initialize the collection of resources and for each Resource you have to initialize the collection of Category.
Do you see ? ;)