RequestFactory: Download entity, add to collection, persist on server, see collection change. Should this work?

39 views
Skip to first unread message

Ryan McFall

unread,
Jan 24, 2012, 4:02:24 PM1/24/12
to Google Web Toolkit
I have an entity class Header, which contains a list of Response
objects. Via a RequestFactory service I create a Header object and
send it back to the client, ensuring that the list of Response objects
is initialized before sending it to the client.

Then, on the client, I use the create method to create several
Response objects and add them to the Header proxy on the client side.
I then send another request to call a method (saveResponses) which
persists the Header object on the server, including a call to .with
("responses"), and then fire the request.

However, on the server side, the response objects are contained in the
list of responses for the Header object in the saveResponses method.

Should I expect this to work? If so, are there any constraints on the
context in which it will work? If not, why not - it seems like this
is basic functionality that should exist. I have gotten around it by
writing methods to explicitly save the Response objects before saving
the Header object, but I don't think I should have to do this.

Thanks in advance for any pointers.

Ryan

Thomas Broyer

unread,
Jan 25, 2012, 5:58:50 AM1/25/12
to google-we...@googlegroups.com


On Tuesday, January 24, 2012 10:02:24 PM UTC+1, Ryan McFall wrote:
I have an entity class Header, which contains a list of Response
objects.  Via a RequestFactory service I create a Header object and
send it back to the client, ensuring that the list of Response objects
is initialized before sending it to the client.

Then, on the client, I use the create method to create several
Response objects and add them to the Header proxy on the client side.
I then send another request to call a method (saveResponses) which
persists the Header object on the server, including a call to .with
("responses"), and then fire the request.

.with() only applies to things sent by the server; so you'd rather use .with("responses") in your first request that retrieve the HeaderProxy, and not the second request that saves it (unless if also returns the HeaderProxy and you want that object to have its responses property populated by the persisted ResponseProxy objects)

However, on the server side, the response objects are contained in the
list of responses for the Header object in the saveResponses method.

Should I expect this to work?  If so, are there any constraints on the
context in which it will work?  If not, why not - it seems like this
is basic functionality that should exist.  I have gotten around it by
writing methods to explicitly save the Response objects before saving
the Header object, but I don't think I should have to do this.

Not sure I understand your issue actually, but RF won't persist your Response objects for you, you have to either persist them individually, or persist them when you persist the Header object.
(see "chained persistence" in http://tbroyer.posterous.com/gwt-211-requestfactory-part-ii, this article is a little old, but still mostly relevant)

Ryan McFall

unread,
Jan 26, 2012, 4:15:22 PM1/26/12
to Google Web Toolkit
> Not sure I understand your issue actually, but RF won't persist your
> Response objects for you, you have to either persist them individually, or
> persist them when you persist the Header object.
> Seehttp://code.google.com/p/google-web-toolkit/issues/detail?id=5389,http://code.google.com/p/google-web-toolkit/issues/detail?id=5724
>  andhttp://code.google.com/p/google-web-toolkit/issues/detail?id=5776
> (see "chained persistence" inhttp://tbroyer.posterous.com/gwt-211-requestfactory-part-ii, this article
> is a little old, but still mostly relevant)

I am using Hibernate on the server, in case I wasn't clear on that.
Let me try to make the issue a little clearer. I am:
1. Downloading a proxy for the header object
(including .with("responses") to make sure that collection of proxies
is loaded),
2. Adding new objects to the responses list for the proxied header
object
3. Sending a request to the server which includes the header object
as a parameter (which causes the associated Hibernate object to be
loaded in place of the proxied object)
4. Asking Hibernate to save the header object.

I've looked through the the issues that you've posted; the comments at
the end of 5839 seem to indicate that some people have gotten this to
work.

When I get to step 3, I first observe RequestFactory creating new
instances of the Response object, and then loading my Header object,
with Hibernate subsequently calling the setter for the response list.
The setter is also called by the RequestFactory framework
(SimpleRequestProcessor$1(AutoBeanVisitor).visitCollectionProperty),
but the list passed to the setter is empty; it seems the value
parameter in the visitCollectionProperty method, which I think should
be the list of ResponseObjects, is null on the server side, but there
definitely are response proxies in the list on the client side before
the header object is sent to the service method.

Ryan

Reply all
Reply to author
Forward
0 new messages