I have the need to capture who created and last modified a number of the 
entities in our system.

Our entites have fields for created by, modified by, creation date, and 
modification date.

What is the recommended way to do this?

My thinking was that I could update these fields using the PrePersist and 
PreUpdate entity callbacks.  Unfortunately, the entity doesn't have access to 
the SessionContext where the information about the caller subject is.

My DAO beans have access to the SessionContext so one approach might be to get 
the caller subject from the SessionContext and set it on a thread-local (via an 
aspect most likely) before manipulating the entities.  Then the entities would 
have that data available.

There are two problems with this.  First, it feels hackish so I'm guessing 
there is a better way.  Second, if there is a UserTransaction running, the 
entities don't actually get persisted (and the callbacks don't get called) 
until the transaction is committed at which point the DAO method(s) are no 
longer in the execution stack and the call is being handled by a completely 
different thread, etc.  So basically, that idea just doesn't work at all.

Seems like this is a pretty common thing to want to do so I'm guessing there is 
a recommended way to do it.

Ideas?

Thanks,
A.J.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3935600#3935600

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3935600


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to