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 <ppod...@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. >