I'm using GWT (2.4) with Spring integrated as in this article. I have problem with getting list of User from database (Hibernate) and populate DataGrid with it. When i call greetingService.allUsers()
method, I'm getting error (onFailure()):
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: The response could not be deserialized
Anybody helps with that? Below some pieces of code. Full working project is here.
public void onModuleLoad() {
// ...
greetingService.allUsers(
new AsyncCallback<List<User>>(){
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
@Override
public void onSuccess(List<User> result) {
GWT.log("SIZE: "+result.size());
dataGrid.setRowData(result);
}
}
);
// ...
}
GreetingServiceImpl
@Override
public List<User> allUsers() {
return userDAO.findAll();
}
User
@Entity
@Table(name = "users")
public class User implements Serializable, IsSerializable {
@Id
private Long id;
// only Strings and one Date
private String login;
private String password;
private String firstname;
private String lastname;
private Date date;
}
Documentation for IncompatibleRemoteServiceException says:
This exception can be caused by the following problems:
- The requested {@link RemoteService} cannot be located via {@link Class#forName(String)} on the server.
- The requested {@link RemoteService} interface is not implemented by the {@link com.google.gwt.user.server.rpc.RemoteServiceServlet RemoteServiceServlet} instance which is configured to process the request.
- The requested service method is not defined or inherited by the requested {@link RemoteService} interface.
- One of the types used in the {@link RemoteService} method invocation has had fields added or removed.
- The client code receives a type from the server which it cannot
deserialize.
In your case is the last point, you have a type which cannot be serialized and deserialized, that's a your User
class is one of them. You should have one transfer object which implements com.google.gwt.user.client.rpc.IsSerializable
interface for transmitting the User object across the network. For further information see: Compatibility with the Java Language and Libraries. GWT RPC method parameters and return types must be transmitted across a network between client and server applications and therefore they must be serializable.