511 words

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

#1
2011-02-07 15:14
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).

 

 

kpanda
kpanda's picture
Joined on 2011-02-07
User Post #1
#2
2011-02-07 18:35

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #127
#3
2011-08-14 16:06

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?

 

Simson
Simson's picture
Joined on 2011-08-14
User Post #1
#4
2011-08-14 16:24

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. I see no way to get those proxy classes on the whitelist of the SerializationPolicy...

Simson
Simson's picture
Joined on 2011-08-14
User Post #2
#5
2011-08-14 18:24

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #523
#6
2011-08-22 11:17

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;
Simson
Simson's picture
Joined on 2011-08-14
User Post #3
#7
2011-08-22 18:26

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #552
#8
2013-04-18 18:49

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.

SailBlue5
SailBlue5's picture
Joined on 2013-04-15
User Post #2

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel