entity with relationships through GWT RPC problem

2020-03-26 08:31发布

问题:

I am using JPA 2.0. (EclipseLink 2.0.2)

If an entity contains relations, for example:

@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
private Collection<Blog> blogCollection;

I am getting the following error when I am sending it through RPC:

com.google.gwt.user.client.rpc.SerializationException: Type 'org.eclipse.persistence.indirection.IndirectList' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = {[]}

回答1:

In general all the Persistence APIs use a technique named code injection, which means that it injects code in your POJOs classes in order to do persistence job. Because this is doing at runtime the GWT compiler was unable to see that, so it can't generates serializers for that types. The solutions is not to send Persistance Classes thru the wire. Instead use DTO (Data Transfer Objects).

Hope this helps. Regards Daniel



回答2:

This error message most likely means that your "Blog" object does not implement java.util.Serializable or com.google.gwt.user.client.rpc.IsSerializable.

RPC and Serializable Discussion