views:

136

answers:

2

In Google App Engine, I can use JDO to persist Java objects into the data store. Can I also use JDO to turn the object into a byte[], so that I can put it into memcache or send it over HTTP?

Clarification: I want to serialize classes that I have already annotated for JDO persistence. Having to use another serialization mechanism seems to needlessly duplicate the effort, and also potentially tricky since JDO/DataNucleus uses bytecode manipulation on its classes to provide features like lazy-loading.

A: 

JDO persists objects to datastores. As part of that it may perform serialisation when a field is marked as "serialized". But that is serialised when stored in the datastore, and deserialised when retrieved from it. If you want to serialise something why not just do it yourself ... why should you need JDO for that?

DataNucleus
I do not want to use another serialization mechanism, because I have already annotated everything for JDO. Also, since JDO uses lazy-loading and "bytecode enhancement", I am not sure if other mechanisms can be used on the same class without conflicts.
Thilo
JDO annotations and bytecode enhancement don't do anything to prevent serialisation. In fact they go to great pains to allow your classes to be used away from a data tier. Either way there is no JDO API for getting some serialised form of a java object
DataNucleus
A: 

It appears you can mark JDO objects as detachable, implement serializable and then when you want to cache them just call detach() and then cache as normal. I haven't tried this but from the discussion groups it seems to work.

There's also some more general discussion of enabling the JDO level 2 cache with memcache. Whether that works is sort of inconclusive but would be a nice solution. More about that: http://groups.google.com/group/google-appengine-java/browse_thread/thread/13cb942ceb97dc/3ab7518edf6a8bc6

Matt Hall