Re: Request Factory Entity Relationships Lazy Loading
The problem with this is you will end up writing a lot of code to get the whole object back. It makes a complex Data Access layer and makes me wonder is it worth using a relational database. If I have to fetch relationships separately (in either layer) why not use a key store database. On Nov 18, 2:47 am, agi wrote: > 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 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.
Request Factory Entity Relationships Lazy Loading
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.
RequestFactory EntityProxyChange events
Hello, I am using GWT 2.1 RC1 and I have managed to make RPC calls to fetch Entities, which come back as their respective EntityProxy, but I can not seem to make an update request fire off a ProxyChangeEvent. Here is my source: */ public class DonorActivity extends AbstractActivity implements BasicActivity, EntityProxyChange.Handler { private static final Logger LOG = Logger.getLogger("donor activity"); protected DonorDisplay display; protected PlaceController placeController; protected final WellRequestFactory requestFactory; @Inject public DonorActivity( DonorDisplay display, PlaceController placeController, WellRequestFactory requestFactory) { this.display = display; this.placeController = placeController; this.requestFactory = requestFactory; } public void start(AcceptsOneWidget panel, EventBus eventBus) { LOG.info("Starting"); display.setActivity(this); panel.setWidget(display); EntityProxyChange .registerForProxyType(eventBus, DonorProxy.class, this); requestFactory.donorRequest().fetchAll().fire(new Receiver>() { public void onSuccess(final List donors) { final DonorRequest donorRequest = requestFactory.donorRequest(); DonorProxy donorEdit = donorRequest.edit(donors.get(0)); donorEdit.setFirstName("first namade some"); donorRequest.persist(donorEdit).fire(); } @Override public void onFailure(ServerFailure error) { LOG.info(error.getMessage()); } }); } public void goTo(Place place) { placeController.goTo(place); } public void onProxyChange(EntityProxyChange event) { LOG.info("Proxy Donor Change"); } } As you can see I'm using GIN to do DI. EventBus is bound to SimpleEventBus. I can see by using firebug that the RPC requests are going through and coming back with JSON. For example: {"result": {"id":"1","lastName":"lastName","email":"someem...@email.com","dob":"52333920","! version":3,"gender":0,"!id":"1","isDeleted":0,"firstName":"first namade some"},"sideEffects":{"UPDATE":[{"!version":4,"! id":"org.thewell.shared.proxy.donorpr...@1"}]},"related":{}} I can see their is a sideeffect and the version number is changing, but still no event is firing off. Also, is there any event automatically fired over the eventBus when a fetch is run or is that the point of a "Receiver"? -- 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.