Hello :
I am using Hibernate 3.1 in managed CMT environment with JBoss 3.2.7. I have to implement a Audit Inteceptor for all the entities for setting modified date time and modified user. Since I have configured Hibernate to work in a managed environment, I am using the getCurrentSession() method in SessionFactory to get the session. Since getCurrentSession() will use the interceptor registered with the SessionFactory, I have to implement a SessionFactory scoped interceptor.
My concerns are :
1. Does the org.hibernate.Intercpetor interface methods onSave, onFlushDirty has to be synchronized for SessionFactoryScoped interceptor implementation since it is mentioned that SessionFactory scoped interceptors must be thread safe.
http://www.hibernate.org/hib_docs/v3/reference/en/html/events.html
2. If it has to synchronized, can it become a performance bottleneck since at every Tx Commit / Rollback these synchronized methods wil be called for every object creation / modification and deletion ?
3. For the modified user information to be audited, I am planning to use a thread local to share the state across the sessions. Is any other elegant methods exists in the case of Session scoped intercpetor ?
4. Other than the method quoted above, is there any elegant method exists for auditing in a managed environment where getCurrentSession() is used instead of openSession() or opensession( Interceptor interceptor ) ? I read about events but the same issues with threading and state exists in that approach also and intercpetor seemed simpler to me.
Am I missing something since I have searched the doc and forum and did not find answer to the above queries. Any pointers / guidance will be really helpful.
thanks and regards,
-- Kannan.