Then two separate requests are made from the browser. I'm hoping that something in the RequestFactory can merge multiple requests - I have to create hundreds of entities at a time, and I don't want to make hundreds of requests!

1 Answer
1

When you call createReq2.fire() at the end, then GWT sends both newEmployee and newEmployee2 in one single request (because they were both persisted in the context of your EmployeeRequest "request"). I personally find the semantics a bit strange, but that's just my opinion.

Addendum by Riley:
The following syntax is equivalent and is much more intuitive:

Oh, how weird. Really weird. Does this mean I have to create some mechanism to schedule a fire() call after I've made all of the persist() calls I want to make? I guess it would be pretty simple to do with a deferred command, but... kind of awkward!
–
Riley LarkFeb 10 '11 at 19:46

@Riley: I would wrap all the code that builds up the request in a method or in its own object. I'd use some variable (or field) to remember the latest request. Then after executing this part of the code, I'd call fire on the latest request. (I wouldn't use a deferred command - it's too shaky, because it's not easy to make sure, when exactly it will execute.)
–
Chris LercherFeb 10 '11 at 20:30

Update: I was making a silly mistake and now your code is working great. I'll think about ways to aggregate requests. Thanks Chris!
–
Riley LarkFeb 10 '11 at 21:00

does this means the two employees will be created in a single atomic transaction, or does it simply mean GWT save bandwidth by sending both changes at once but each of them is persist in different transaction and may fail or succeed individually?
–
Ido RanSep 5 '11 at 20:55

That depends on your service layer and how your server side persist method works. If your persist method is wraped within its own transaction, than every employee is saved in its own transaction of cause.
–
PeterJan 18 '12 at 14:29