It does keep track, but you might need to experiment a bit with your 
persistence.xml. In my case (doing lots of detached work), I needed the 
following settings:

            <property name="openjpa.DetachState" 
value="loaded(DetachedStateField=true)"/>
            <property name="openjpa.Compatibility" 
value="IgnoreDetachedStateFieldForProxySerialization=true"/>

Be aware that some of those settings radically change the way OpenJPA works 
internally. But otherwise detached, merging, etc does not really work as this 
area is pretty under-specced.
I also remember that I needed to fix a few things to get the correct state in 
OPENJPA-1873. Not sure how much of this patch got already committed (got my 
time eaten up by a few other Apache projects lately).

LieGrue,
stru 

--- On Sat, 7/16/11, Bengt Rodehav <[email protected]> wrote:

> From: Bengt Rodehav <[email protected]>
> Subject: Re: Audit log with OpenJPA
> To: [email protected]
> Date: Saturday, July 16, 2011, 8:40 PM
> Did you have a suggestion regarding
> this Pinaki - or does OpenJPA only keep
> track of changed values - not the whole original object?
> 
> /Bengt
> 
> 2011/7/15 Bengt Rodehav <[email protected]>
> 
> > I don't understand Pinaki.
> >
> > The "this" pointer is the current version of the
> object (the one that is
> > about to be persisted) right? I want the previous
> version of the object. I
> > have used your code from the blog (and added some of
> course) like this:
> >
> > *
> >>>
> >>>     PersistenceCapable
> currentState = (PersistenceCapable) this;
> >>
> >>     StateManagerImpl sm =
> (StateManagerImpl)
> >>> currentState.pcGetStateManager();
> >>
> >>     SaveFieldManager sfm =
> sm.getSaveFieldManager();
> >>
> >>     PersistenceCapable
> oldState = sfm.getState();
> >>
> >>     EntityBase old =
> (EntityBase) oldState;
> >>
> >>     old = (EntityBase)
> oldState;
> >>
> >>
> >>>     AuditLogEntry entry =
> new AuditLogEntry();
> >>
> >> 
>    entry.setSerializedState(cAuditLog.serialize(old));
> >>
> >> 
>    entry.setEntityId(old.getId());
> >>
> >> 
>    entry.setCreatedWhen(old.getCreatedWhen());
> >>
> >> 
>    entry.setCreatedBy(old.getCreatedBy());
> >>
> >> 
>    entry.setUpdatedWhen(old.getUpdatedWhen());
> >>
> >> 
>    entry.setUpdatedBy(old.getUpdatedBy());
> >>
> >> 
>    entry.setVersion(old.getVersion());
> >>
> >>
> >>
> >>     EntityManager em =
> OpenJPAPersistence.getEntityManager(this);
> >>
> >>     em.persist(entry);
> >>
> >>
> >> *
> >
> >
> > cAuditLog is an object which uses Gson to serialize
> the object to a String.
> >
> > The problem is that only those fields that I have
> actually updated are
> > initialized in the variable "old". The rest of the
> fields are uninitialized.
> > In my case I do not only want to save the changed
> fields but the whole
> > object. How can I make sure that "old" is fully
> initialized?
> >
> > /Bengt
> >
> > 2011/7/15 Pinaki Poddar <[email protected]>
> >
> >> The whole object is *this* pointer on which you
> received the callback.
> >> You can safely cast it into PersistenceCapable and
> get to know all about
> >> its
> >> state.
> >>
> >> Please see the blog post -- it has some toy code.
> >>
> >> -----
> >> Pinaki Poddar
> >> Chair, Apache OpenJPA Project
> >> --
> >> View this message in context:
> >> http://openjpa.208410.n2.nabble.com/Audit-log-with-OpenJPA-tp6557932p6585154.html
> >> Sent from the OpenJPA Users mailing list archive
> at Nabble.com.
> >>
> >
> >
>

Reply via email to