Michael Strasser
|
Posted: September 16, 2010 23:55 by Michael Strasser
|
|
I would appreciate any comments from forum members on this issue. ProblemI need to implement a database record auditing scheme in JPA to replace an existing one. The requirement is to include user and timestamp when each record is created and modified, into existing columns I am basing my design on a a blog entry I found that describes what I want to achieve: Reusing JPA models using embedded entities and composition. DesignI will have PDOs and stateless EJBs to manage them. EJBs will be called with container-managed security. I plan to create an embeddable type and an entity listener with Who is the user?The complication is getting the user information. (The blogged example I found relies on using Pre-persistThis seems easy: the EJB sets the Pre-updateThe EJB can specify a current user when it retrieves an entity but we only want to update the entity if one of the business fields changes (not an auditing field). Use a transient fieldThis is my current proposed solution that covers both presist and update. The
The embeddable type is:
An example entity includes:
The entity listener class is:
The management EJB includes code like this:
Notes
|
Adding current user information to JPA entities
Replies: 1 - Last Post: September 17, 2010 10:59
by: Michael Strasser
by: Michael Strasser
showing 1 - 2 of 2
Michael Strasser
|
Posted: September 17, 2010 10:59 by Michael Strasser
|
A follow-upI tried to automate things a bit by creating an EJB interceptor that would set the current user after an EJB method that returned one of my entities. I had a Service Façade EJB (outer) that called an entity management bean with transaction attribute What I found was unexpected:
I found the same with both Hibernate and Toplink Essentials on OC4J. |
Replies: 1 - Last Post: September 17, 2010 10:59
by: Michael Strasser
by: Michael Strasser






