On 5/18/06, Andrus Adamchik <[EMAIL PROTECTED]> wrote:
On May 18, 2006, at 6:54 AM, Tomi NA wrote: > I have a couple of questions about this. > First, is there any special reason the templates, the DataObject and > the ObjectId class don't have a serialVersionUID? We should probably add serialVersionUID to all serializable classes (and somehow add it to cgen templates) - this may be an improvement to the future versions. But the JVM should not throw an exception when it is absent either. So are you getting some kind of warning, or is this an exception?
It is just a warning, but it seems that the serialization process fails as I get null values when I deserialize. I thought the missing UID might be the reason.
> Second, is it possible at all to successfuly serialize a class > representing a database entity? Absolutely. Serialization of DataObjects worked since Cayenne 1.0. The easiest way is to serialize the entire DataContext; if you serialize individual objects, you will have to manually reattach them to the context on deserialization (e.g. by calling 'localObject').
> Won't the serialization algorithm get > just about the entire database, following the bean getters?
No, Java serialization does not use getters, it serializes fields directly. However IIRC Java bean serialization does - so this can be a problem.
Hmm...I'm sorry to hear that. The problem is, I have a panel and a bean (presenter, model, if you will) and I bind them using jgoodies binding. Some of the bean fields are cayenne DataObjects. I have these kinds of panels all over the app, but I need to serialize just a couple of them: the point is to save a part of the frame (panel) state. Now, to the fields-bean properties issue...If I deserialized the entire context, as you suggest, what would that do for me in terms of (de)serializing my own bean containing private fields with their respective public get/set pairs? How should I go about serializing/deserializing such objects? All I have at my disposal right now is a stream to which I can write to or read from, depending on whether I'm serializing or deserializing. I'm not clear on what happens when I write an object to such a stream, no matter the fact I have a serialized DataContext.
> I'd very much appreciate a comment on the topic, as well as a prod in > the right direction concerning cayenne DataObject serialization. > Should I be looking at decode/encodeXML? If you don't care about the format, Java binary serialization should be more efficient than XML.
I couldn't care less. :) t.n.a.
