> -----Ursprüngliche Nachricht-----
> Von: David Goodenough [mailto:david.goodenough@btconnect.com]
> Gesendet: Donnerstag, 7. Juli 2011 16:36
> An: users@openjpa.apache.org
> Betreff: Re: Audit log with OpenJPA
>
> On Thursday 07 Jul 2011, Bengt Rodehav wrote:
> > I'm using OpenJPA for persistence and would like to audit log any
> > changes made to my entities. I serialize the objects to JSON (with
> > Gson) and store them in a separate table in the database. Since the
> > audit log needs to have the correct id's, the audit logging
> must take
> > place after the entity has been persisted.
> >
> > I was hoping I could use the @PostPersist and @PostUpdate
> life cycle
> > callbacks for this. I do seem to have the right information
> available
> > and the serialization works fine but I don't know how I can
> persist my
> > audit log entries at this point. From what I've read, I'm
> not allowed
> > to use the entity manager in a "Post" lifecycle callback which of
> > course makes this hard.
> >
> > What do you recommend? Is there a good place in JPA/OpenJPA where I
> > automatically can trigger the storing of an audit log entry as
> > described above. Of course I can move this logic up from the
> > persistence layer to a place where I can first have the
> entity manager
> > persist my entity and then explicitly call another service
> to do the
> > audit log. However, this is a pretty general mechanism that I would
> > like to have automatic support for in my framework which is why I
> > would like to have it pushed down into the persistence layer.
> >
> > Any ideas?
> >
> > /Bengt
> You could of course cheat.
>
> While you can not access the entiry manager, there is nothing
> to stop you using JDBC. It would probably not be a good idea
> to access a table that JPA is using, but if this audit trail
> is write only for this app and only read elsewhere that would
> solve the problem.
>
> David
>
Or cheat even bigger and use an after (insert/update) trigger on the Table to insert log entries
into your log.

John
----
Who is General Failure, and why is he reading my hard disk?
|