Hi,
When I save my business object (e.g. Employee), I stamp the record with a "last_modified_date" value and a "last_modified_user" reference. (which links to the User class of system users). This allows my reports to say
Last modified by wglass 5/4/04.
Right now, every time my business logic saves the Employee object, it has to update these two fields. It occurs to me that it'd be nice if my domain logic (e.g. the Employee object) could handle this automatically.
To make this work, I can implement Lifecycle use the onSave and onUpdate methods. This will allow me to set the "last_update_date", but it looks impossible to set the "last_modified_user" field as it has no access to the current user object (stored in the HttpSession).
Here's my question. When I open the Hibernate session at the start of my HTTP request, I'd like to attach the user object to the Hibernate session. Then, all my business objects can have access to it in the onSave/onUpdate methods for automatic timestamping. This would simplify my code as it would allow each persistent object to manage the "last modified" info instead of the business logic attaching the user and stamping the date. I'm looking for a setAttribute/getAttribute type of functionality.
Is this feasible? Recommendations appreciated.
Best, WILL
|