Hi I had this problem as well. I haven't found perfect solution.. What I have done is while retrieving data from the database so e.g. in findEntity(Long id) method I am forcing persistent layer to return my collection immediately: Entity findEntity(Long id) { // open transaction, get entityManager etc. // ...
Entity obj = entityManager.find(id); // force retrival of collection obj.getDonations().size(); // handle transaction and entitymanager etc. //... } I will be very glad to find out how to make it in a better way:) On Nov 18, 1:02 am, PJ Herring <pjh...@gmail.com> wrote: > So I've been working on this problem with RequestFactory and Lazy > Loading. I am using a Service Layer to deal with operations on Domain > Objects. I ran into a problem when I was trying to "merge" an object > with my Hibernate Domain layer. Hibernate was throwing a "lazy > loading" error ("Failed to lazily initialize a collection"). The > problem was when I fetched an object via RequestFactory it did not > come with its relationships. So if I had a Donor with a collection of > Donations, the Donations do not come with the initial fetch unless > specified (i.e. > requestFactory.donorRequest().fetch(id).with("donations")). When I > removed the relationship from the Proxy Domain Object (so removing the > methods getDonations and setDonations from the DonorProxy), I did not > have this problem. The merge worked fine. Why is this the case? > > Second, if this is the case it would seem beneficial to remove > relationships that you would normally want to lazy load from the > proxies and just make an explicit call to load up the collection. So > remove the getDonation and setDonation from the DonorProxy and when I > need those donations just make a call with the donorId to get them. > This seems counter intuitive to me, but seems also not like a terrible > idea. Basically I am trading of between having to make explicit calls > to load OneToMany relationships and being able to do merge's. AM I > CRAZY? -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.