-
1. Re: Audit Interceptor with State
pmuir Nov 29, 2006 7:47 AM (in response to kevin.genie)I implemented something similar to the audit log code on the hibernate website. It's an extension to EntityHome, and will scan over the entity being saved, logging new values (and old values if changed and an update is occuring) if the property is marked @Auditable. It will follow associations depending on the CascadeType and works with collections. Oh, and it outputs the log as a trinidad tree table, but thats easily customisable.
I can post the code if you are interested (but beware, it's mostly complete and mostly works but I'm sure there are lots of bugs...) -
2. Re: Audit Interceptor with State
cwash Nov 29, 2006 8:33 AM (in response to kevin.genie)I'm interested in this type of functionality, too. In the past I've used a Hibernate Interceptor and had an extension to my base model object that encapsulated the fields I wanted audited. I was able to do a type check in the interceptor code and persist the encapsulated audit log entries there.
Too much of a Seam n00b to have done this yet, though. -
3. Re: Audit Interceptor with State
kevin.genie Nov 29, 2006 8:50 AM (in response to kevin.genie)Hello,
Can u pls post ur code ? Again, how will i persist the audit data from the interceptor / listener ? (i.e how do i get a entitymanager for that ? look up the entitymanager factory and get the em ?)
Thanx
Kevin -
4. Re: Audit Interceptor with State
pmuir Nov 29, 2006 4:08 PM (in response to kevin.genie)Well I didn't do this through an interceptor/listener, but via an extension of EntityHome from the Seam Framework. I just override the persist, update, remove methods in EnitityHome, call my audit logger, and then continue as normal. So, the only extra thing you need is a separate EntityManager instance for accessing the old version of the object for comparison (just configure another ManagedPersistenceContext in components.xml).
I'm just tidying the code a bit to make it more useable, and stripping the presentation stuff out (as that uses trinidad) and then I'll post it - probably tomorrow. -
5. Re: Audit Interceptor with State
kevin.genie Nov 30, 2006 11:30 PM (in response to kevin.genie)Hello,
I was just reading through the EntityHome Manager pattern and it seems that for that to work I have to use SeamManagedPersistenceContext. In my application we are not using SeamManagerPersistenceContext and are relying on EJB container for Tx demarcation. In this case, what will be the options left ?
Thanx,
Kevin -
6. Re: Audit Interceptor with State
gavin.king Nov 30, 2006 11:38 PM (in response to kevin.genie)This stuff is meant to be used with Seam-managed tx/pc. If you wanted to use it with container-managed PC/tx, you could do it, but you would need to inject the EntityHome into a session bean component that does tx demarcation.
-
7. Re: Audit Interceptor with State
gavin.king Nov 30, 2006 11:39 PM (in response to kevin.genie)(The reason is that fine-grained method-level tx demarcation is an antipattern - you want to do all your work for a request in the same tx.)
-
8. Re: Audit Interceptor with State
kevin.genie Dec 1, 2006 4:20 AM (in response to kevin.genie)Hello Gavin,
<<(The reason is that fine-grained method-level tx <<demarcation is an antipattern - you want to do all <<your work for a request in the same tx.)
I didn't understand what you have said ? Can u pls give a detailed explanation ? Are you referrring to the pattern where from the controller you are forced to do all the work in a single ejb call since you cannot make two EJB calls in the same Action method because of Tx getting splitted ? If that is the case, is there a way this can be done in Seam ? If we are using Session bean methods as action methods, then here also we have to do all the work in that method itself; am i right ?
Thanx
Kevin -
9. Re: Audit Interceptor with State
pmuir Dec 1, 2006 11:45 AM (in response to kevin.genie)Back to the original topic of audit logging. Here is my code. I'm pretty sure there are bugs in the logging code (especially in the list comparison) so if you spot stuff please let me know.
http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamAuditHome -
10. Re: Audit Interceptor with State
kevin.genie Dec 6, 2006 3:56 AM (in response to kevin.genie)Thanks very much. I was on vacation. I am going to work on it today itself.
-
11. Re: Audit Interceptor with State
gavin.king Dec 11, 2006 1:05 AM (in response to kevin.genie)"kevin.genie" wrote:
Hello Gavin,
<<(The reason is that fine-grained method-level tx <<demarcation is an antipattern - you want to do all <<your work for a request in the same tx.)
I didn't understand what you have said ? Can u pls give a detailed explanation ? Are you referrring to the pattern where from the controller you are forced to do all the work in a single ejb call since you cannot make two EJB calls in the same Action method because of Tx getting splitted ? If that is the case, is there a way this can be done in Seam ? If we are using Session bean methods as action methods, then here also we have to do all the work in that method itself; am i right ?
What I mean is that if you let EJB demarcate the txn, and if you have lots of little calls from the view to the session beans while rendering a single page, you will get many little transactions instead of a single big one. -
12. Re: Audit Interceptor with State
kevin.genie Dec 13, 2006 8:45 AM (in response to kevin.genie)Thanks very much Gavin, for spending time in explaining that.
For the auditing part, I am now trying to do it thru Hibernate SessionFactory level Interceptor. -
13. Re: Audit Interceptor with State
awhitford Aug 10, 2007 7:15 PM (in response to kevin.genie)So in the end, how did you do this Kevin? Did you use Pete's strategy, or end up using Hibernate Interceptors?
-
14. Re: Audit Interceptor with State
apushadow Aug 16, 2007 10:55 AM (in response to kevin.genie)Heya Pete--
I'm trying to use your solution (from here http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamAuditHome)...
I copied the orm.xml into my project and annotated a bunch of stuff in my User object as @Auditable. When I start up my app server (OC4J), the auditlog and auditlogdetail tables are created, but when I update my user objects (with entityManager.merge()...is that a problem?), nothing is inserted into the audit tables.
Is there something else I need to add to my application to make this work? It's probably something to do with what you wrote on the wiki: "As long as you control your entities through an AuditHome? (a drop in replacement for EntityHome?) logs will be created."...I don't know how to do this, though.
Any direction would be appreciated,
--Rich