persistence@glassfish.java.net

Re: Serializable Entities

From: Shelley <randomshelley_at_gmail.com>
Date: Wed, 21 Nov 2007 14:21:39 -0600

I am using field-based access for my entities and would like to
implement custom serialization [1] (which involves marking all
instance variables as transient and overriding the default
serialization protocol by specifying the
writeObject(ObjectOutputStream out) and readObject(ObjectInputStream
in)). As mentioned, the fact that JPA does not persist transient
variables is the reason for my question - is it common practice to use
default serialization for entities, or do I need to use property-based
access so that I can write my own custom serialization?

[1] http://java.sun.com/developer/technicalArticles/Programming/serialization/


On Nov 21, 2007 2:05 PM, Stephen Connolly
<stephen.alan.connolly_at_gmail.com> wrote:
> instance variables marked transient will neither be serialized nor
> persisted by JPA.
> what are you keeping in these transient fields that cannot be derived
> from the non-transient fields?
>
>
>
> On 11/21/07, Shelley <randomshelley_at_gmail.com> wrote:
> > What are the best practices for serializing entities? My entities use
> > field-based access, so custom serialization will not work because this
> > requires that the instance variables are declared 'transient' (which
> > indicates to the persistence provider that such fields are not to be
> > persisted). Is default serialization generally a recommended practice
> > for entities, or will I need to refactor my entity classes for
> > property-based access in order to customize the serialization?
> >
>