ObjectDB ObjectDB

GWT RPC is throwing serialization exception when I have object db date value

#1
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'objectdb.java.util.Date'
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 =Sat Jan 29 00:00:00 PST 2011   

at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)

 

I have implemented serializarion for all of mine Data Transfer Object. But still I am getting this error.

Note: (In gwt RPC you cannot use the Entity objects, You need srializable DTO objects to handle CRUD operations).

 

 

edit
delete
#2

The objectdb.java.util.Date class is a subclass of java.util.Date that ObjectDB uses in order to track changes. It implements java.io.Serializable but probably this is not sufficient for GWT because Date is a special data type. You may have a similar problem with collection and map fields in your entities.

The solution for date should be using ordinary java.util.Date.

ObjectDB replaces objectdb.java.util.Date with java.util.Date automatically on ordinary serialization. Following your post - a new build was released (2.0.5_02) in which ObjectDB performs this replacement operation also on detachment (rebuild and enhance your classes again to use this).

So you can use now detached entity objects. Maybe you may even use detached entity objects directly in GWT with no DTO.

 

ObjectDB Support
edit
delete
#3

Hello,

I have a similar problem but with java.util.ArrayList instead of java.util.Date.

"The solution for date should be using ordinary java.util.Date."

I am using java.util.LinkedList (and not objectdb.java.util.ArrayList) in my code. But in the database it seems to be stored a a objectdb.* type. Persisting new objects seems to be ok but retrieving data from the database does not work.

I'm using objectdb 2.2.8 and GWT 2.3.0 with embedded jetty in Eclipse. Stack trace is attached.

Any ideas? Is there any way to avoid the usage of those proxy classes?

 

edit
delete
#4

Hm, interesting. I just found this: http://www.objectdb.com/java/jpa/entity/types#Proxy_Classes_

"Most applications are not affected by this, because proxy classes extend the original Java classes and inherit their behavior."

Using Rpc in GWT  is affected. sad I see no way to get those proxy classes on the whitelist of the SerializationPolicy...

edit
delete
#5

Have you tried detaching entities before serializing them using GWT?

objectdb.java.util.LinkedList is replaced with java.util.LinkedList automatically during detachment, so detached entity objects can be serialized using GWT.

 

ObjectDB Support
edit
delete
#6

Yes, detaching does work for this issue, thank you! But now I have to set fetchtype and cascadetype explicit (which is no problem), otherwise the List will alway be empty after detaching.


@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Transaction> transactions;
edit
delete
#7

That's true. In JPA, objects that have not been loaded before detachment are unavailable after detachment. So you have to load the collection, and using EAGER fetch mode is one way to do that.

ObjectDB Support
edit
delete
#8

I ran in to this problem but didn't want to hassle with detaching.  In my case I have a bunch of data transfer objects that I load my entities in (instead of RPCing my entities) and in the set methods or constructor (depending on how I do it) I just make sure I create a new java.util.Date() object and set the time using the old objectdb.java.util.date.  SO I have something like

 

java.util.Date DateDTO = new java.util.Date(ObjectDBDate.getTime());

 

This works for how I do things in GWT, but might not work for you.

edit
delete

Reply

To post on this website please sign in.