openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bengt Rodehav <be...@rodehav.com>
Subject Re: Audit log with OpenJPA
Date Sat, 16 Jul 2011 20:40:33 GMT
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 <bengt@rodehav.com>

> 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 <ppoddar@apache.org>
>
>> 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.
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message