-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Implementing Audit Logging using EJB3
PostPosted: Tue Aug 30, 2005 11:56 pm 
Newbie

Joined: Wed Jul 27, 2005 7:53 am
Posts: 4
I would like to implement "audit logging" exactly as described in the Hibernate in Action book, section 8.3.2, ie create a row in an audit table every time any instance of certain entity classes is inserted/updated in the db. I'm not interested in tracking exactly what field changes have occurred, but I do need to insert the id of the user performing the change so database triggers aren't sufficient.

However I would like to do it using EJB3 persistence APIs only.

Following some experiments it looks like @PostPersist is equivalent to the Interceptor callback "onSave" and @PostUpdate is equivalent to "onFlushDirty". However the creation of the audit log row can't be done in those methods for the reasons described in the book: auto-generated IDs haven't been allocated yet.

I can't see any EJB3 equivalent of the Interceptor.postFlush callback.
And furthermore an EJB3 EventListener target class is required to be stateless, so there isn't any place for the @PostPersist/@PostUpdate callbacks to store the list of updated classes for the postFlush operation.

So right now I'm stumped. Can anyone suggest how "audit logging" can be done in EJB3?

And if it *can't* be done with pure EJB3 APIs, can someone suggest how to use hibernate-specific calls to do the same when running within JBoss 4.0.3-RC2? Ideally I would like to be using persistence context injection but even that's negotiable...

Many thanks...


Top
 Profile  
 
 Post subject: Old-style Interceptor supported in EJB3 in hibernate3.1beta3
PostPosted: Wed Aug 31, 2005 1:37 am 
Newbie

Joined: Wed Jul 27, 2005 7:53 am
Posts: 4
I spotted this which might be one solution to my problem:
http://opensource2.atlassian.com/projec ... 4?page=all

It appears that configuration property
Code:
  hibernate.ejb.interceptor

can be set in the persistence.xml file to specify some class which implements org.hibernate.Interceptor. I presume that an instance of that class will then be created and attached to every EJB EntityManager created by Hibernate.

According to the bugreport above, this feature has been committed to CVS and will be available in hibernate 3.1-beta3.

I would still be interested in hearing about any pure-EJB3 solution to this, ie one that doesn't require implementing an org.hibernate interface directly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.