openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bengt Rodehav <>
Subject Re: Audit log with OpenJPA
Date Wed, 27 Jul 2011 09:02:40 GMT
Hello Pinaki,

Thanks for looking into this. What you are suggesting seems useful and it
would be really nice if this functionality is supported in the future.
However, I can't see how it directly solves my problem. What I'm trying to
do in my audit log is to save a serialized form of my entity - the whole
entity and not just the dirty fields. My intention was to use JSON (with
Gson) for this. I'm sure there are many different approaches to an audit log
(as can be seen from this long conversation) but my rationale is:

I want an easy way to show the user exactly what a previous version looked
like. Either I save the complete previous version or I have to reconstruct
it when showing it to the user. The former seems easier. Furthermore, audit
logging is used for rather static (as opposed to transactional data) which
means that there is no problem using up a few more bytes.

Clearly indicating what fields were changed is a bonus. If I could save both
a serialization of the previous version and some metadata indicating what
fields were changed that would be perfect. I would probably have to drop
JSON and go for XML instead then.

The API extension you're proposing will give me information about the dirty
fields but I can't clearly see how I can create a serialization of the
previous version for the entity.

2011/7/27 Pinaki Poddar <>

> Hi Bengt,
>  I find that accessing the old state is possible using internal mechanics
> -- but could not find a way to do it from the current API unless I expose
> some internals. After a bit of deliberation, I am suggesting that we add
> the
> following method to SaveFieldManager.
>    /**
>     * Gets the old values for the given list of fields provided they are
> dirty.
>     * @param fields a list of field names. null implies all dirty fields.
>     * @return a map of old values for each given field, if they are dirty.
>     * The map values are a pair of objects in an array -- the 0-th element
>     * is the old value and the 1-st element is the current value.
>     */
>    public Map&lt;String, Object[]&gt; getOldValues(String...fields)
> I have tested your supplied classes with the classes you supplied.
> If you do not mind being in the bleeding edge, i.e. if you can consume
> OpenJPA nightly builds, then I will commit the changes.
> -----
> Pinaki Poddar
> Chair, Apache OpenJPA Project
> --
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

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