Q: Is there any way of accessing the SessionContext object of a session bean, which has created (in whatever way) an entity, from within the actual entity object?
Background: In my app, when I insert or update rows via a entity created from a session EJB, I'd like to set a column to a user id derived from the caller Principal object (as returned by SessionContext.getCallerPrincipal( ) ).
I could set this using code in all the session EJBs in every entity that's inserted/updated, but this line of code is easilly forgotten.
If I could access the SessionContext from the entity class I could add the code there when writing the entity class and not every time I use it from a session EJB.
I've tried "@Resource SessionContext ctx;" in the entity, but this gives null.