views:

69

answers:

1

Hi

Is it possible (in a clean fashion) to create an audit interceptor in hibernate 2.1 and pass in a domain context to it?

What I would like to achieve is to set a Date Time (can be done easy peasy - found loadsa articles after a quick google), but setting an object e.g. a user who created the item, or altered an entity I have yet to find anything which covers this.

Since I will not know the object at application request/start up (which is where i have to register the nhibernate interceptor), does anyone know of a suitable workaround?

Thanks in advance, Mark H

+2  A: 

You can store the user in the current session (HttpContext.Session) or use thread local data. It can then be accessed by the listener. If you go for the thread local approach, you will need to set if for each request, for instance with an HttpModule. Not perfect, but that's how I've seen it done in java (not exactly the same, but a similar approach).

ewernli