GWT Deserialisation of Persistent Entities (JPA)
Posted
by
slartidan
on Stack Overflow
See other posts from Stack Overflow
or by slartidan
Published on 2011-01-11T09:56:16Z
Indexed on
2011/01/13
2:53 UTC
Read the original article
Hit count: 220
Hi everyone,
I am currently developing Java/GWT-application which is hosted on a weblogic application server. I am using EJB3.0 with EclipseLink as persistence layer. Sadly my GWT has problems to deserialize persistent entities.
It might be helpful for you to know, that I
- have the EclipseLink-Library in my classpath (including
javax.persistence.Entity
) - am not recieving the persistence objects from a database or persistence-manager - I am creating the objects with standard java code
- use Eclipse IDE for Java EE Developers for development and deploying and I am compiling my GWT code with the GWT-Plugin (GWT 2.1.0) - my source code is split up in several projects
- am pretty sure, that the problems occures on client side, since the HTTP response of my server is the same in my working and in my not working example
- tried to patch
javax.persistence.Entity
and tried to include several libraries which includedjavax.persistence.Entity
but nothing was helping
In my server provides a list of instances of class SerialClass
; the interface looks like this:
public interface GreetingService extends RemoteService {
List<SerialClass> greetServer();
}
My onModuleLoad()-Method gets those instances and creates a browser-popup with the information:
public void onModuleLoad() {
GreetingServiceAsync server = (GreetingServiceAsync) GWT.create(GreetingService.class);
server.greetServer(new AsyncCallback<List<SerialClass>>() {
public void onFailure(Throwable caught) {
}
public void onSuccess(List<SerialClass> result) {
String resultString = "";
try {
for (SerialClass serial : result) {
if (serial == null) {
resultString += "null ";
} else {
resultString += ">" + serial.id + "< ";
}
}
} catch (Throwable t) {
Window.alert("failed to process");
}
Window.alert("success:" + resultString);
}
});
}
My server is looking like this:
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {
public List<SerialClass> greetServer() throws IllegalArgumentException {
List<SerialClass> list = new ArrayList<SerialClass>();
for (int i = 0; i < 100; i++) {
list.add(new SerialClass());
}
return list;
}
}
Case 1 => everything works fine
I am using this SerialClass
(either without any annotation, or with any annotation other than Entity - for example javax.persistence.PersistenceContext
works fine):
//@Entity
public class SerialClass implements Serializable, IsSerializable {
public int id = 4711;
}
The popup contains (as expected):
success:>4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711<
The data sent over HTTP looks like this:
//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]
Case 2 => its not working at all
I am using this SerialClass
:
@Entity
public class SerialClass implements Serializable, IsSerializable {
public int id = 4711;
}
My popup contains (THIS IS MY PROBLEM):
success:>2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null
The data sent over HTTP looks like this (exactly the same!):
//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]
There is no suspicious logging output - neither on server, nor on client. All HTTP-responses have return code 200.
My current workaround
I am going to try to create transfer objects as a copy of my SerialClass - those transfer objects will look exactly the same, but will not have the @Entity annotation.
Alternatively I could try to use the RequestFactory
(thanks to @Hilbrand for the hint).
I really don't know how to solve that problem and I'm really thankful about any suggestions, hints, tips, links, etc.
© Stack Overflow or respective owner