GWT RequestFactory with Spring, JPA and Hibernate?

This is a posting about all things I had to do to get the GWT 2.4.0 RequestFactory to work with my spring based application. And it will explain why I finally gave up and switched to REST.

Server Part

Most JPA / Hibernate based apps do have a super entity declaration.  It takes care about the unique id and version in this case. These attributes are also important for the RequestFactory!

BaseEntity.java:


The entities we want to edit online are Customer and Address:

We have a basis dao interface and implementation:

And would normally have a customer dao interface / impl without any more methods. But I want to use the CustomerDAO as the server side implementation of the RequestContext methods of my Customer. This would be no problem, but the RequestFactory scans only the actual given Service class for method names and therefore my CustomerDao looks like:

Bringing Spring and RequestFactory together:

and

Client part

On the client side, we need of course our proxy interfaces:

and

As you can see the AddressProxy extends the ValueProxy interface. Since I don’t want to handle the address persistence with my own dao and RequestContext, I used this interface and let the server take care about persisting it.

The next thing you need is the customer RequestContext:

And the Factory:

These are mainly all classes you need in the frontend.

Using it in the front end

Code from my application factory:

Code from my NewCustomerEditor (the presenter part of the new customer activity). The entry method is doUpdateForPlace since I use Activities and Places:

Important:

  • Always create a new CustomerRequestContext when a request was made.
  • When re-using a EntityProxy object (like I do for search), also send around the corresponding RequestContext with which it was created.