OpenJPA GWT serialization problem.

201 views
Skip to first unread message

dparish

unread,
Nov 8, 2010, 8:17:01 PM11/8/10
to Google Web Toolkit
I have an entity with a member like this:


@Entity
public class Foo implements Serializable{

@OneToMany(mappedBy="foo",targetEntity=InternalText.class,
fetch=FetchType.EAGER) // I tried Lazy too.

private ArrayList<InternalText>internalTextEntries;


When I try to use Foo I get this error:


Throwable occurred:
com.google.gwt.user.client.rpc.SerializationException: Type
'org.apache.openjpa.util.java$util$ArrayList$proxy' 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 =
[blah.blah.entities.InternalText@36ae36ae,
blah.bhla.entities.InternalText@3fca3fca,
blah.blah.retain.entities.InternalText@42474247,
blah.blah.entities.InternalText@48724872]
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:
610)
at
com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:
129)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter
$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:
534)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:
700)


From what I can tell openjpa is creating a helper representation of
ArrayList that it uses to assist in monitoring and lazy loading the
child table. I've tried eager and lazy fetching.

I tried this:

ArrayList<InternalText> newText = new ArrayList<InternalText>();
for (InternalText textItem: foo.getInternalTextEntries()) {
newText.add(textItem);
}
foo.setInternalTextEntries(newText);


It got past my error, but then the next layer down had trouble (Date
in the InternalText class)

Type 'org.apache.openjpa.util.java$util$Date$proxy' was not included
in the set of types which can be serialized by this
SerializationPolicy



David Chandler

unread,
Nov 8, 2010, 9:20:01 PM11/8/10
to google-we...@googlegroups.com
Hi dparish,

There are three issues here:

1. GWT needs a fully populated object graph to send back to the
client. Lazy fetching will not work across the client / server
boundary, so you must ensure that your code fetches all relations
eagerly (via an annotation or a separate call if needed).

2. JDO and JPA implementations use proxy classes for objects attached
to a persistence manager. Before they can be sent back to the client,
you must detach all objects from the PM.

3. Even then, GWT won't be able to serialize any types for which it
doesn't know the source (like App Engine's Key class). The open source
Gilead project and others like Objectify provide GWT wrappers for
these.

HTH,
/dmc

> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

--
David Chandler
Developer Programs Engineer, Google Web Toolkit
http://googlewebtoolkit.blogspot.com/

dparish

unread,
Nov 9, 2010, 7:59:14 AM11/9/10
to Google Web Toolkit
Thanks David.

I tried LAZY and EAGER. Both caused the problem.

For #2, that seems promising. There's an EntityManager clear method,
but that would affect all threads using the entity manager. Any
thoughts on how to do that detach?
> > For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.

dparish

unread,
Nov 9, 2010, 8:12:13 AM11/9/10
to Google Web Toolkit
I tried using em.clear(). I did this after loading and accessing my
object. I also changed my fetch type to EAGER. Sadly it still fails ;
(

-Dave

David Chandler

unread,
Nov 9, 2010, 1:31:55 PM11/9/10
to google-we...@googlegroups.com
In JDO, there are pm.detachX() methods you can use to do this. In JPA,
it appears detachment is automatically done via an annotation, but the
detached objects will still contain non-serializable stuff. Details
here:

http://timepedia.blogspot.com/2009/04/google-appengine-and-gwt-now-marriage.html

HTH,
/dmc

> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages