Hello,
the standard hibernate way to add an interceptor to a session is:
SomeInterceptor int = new SomeInterceptor();
int.setStateDependentFromCurrentUserOperations(...);
Session session = sf.openSession( int );
Which allows to build an interceptor passing it whatever information is needed for its jobs (ex. auditing what the current logged user is doing).
Using HibernateContext it's only possible to pass a reflection generated interceptor, specified in xml, with no way to pass it some state dependent informations.
I've seen some pattern on the forums forcing you to add special infos to all the hibernate objects (the auditing example) but I would prefere to not pollute my objects with additional fields.
I would really like to be able to manually add an interceptor to a session using the HibernateContext class, so I was thinking something like:
HibernateContext.java
public static Session getSession(String name, Interceptor interceptor)
... and ...
private static Session generateSession(String name, Interceptor interceptor) throws HibernateException
The code would check to see if interceptor is != null, and if it is, it would use the factory.openSession(interceptor) instead of factory.openSession().
I still have to find where it looks for the HibernateInterceptor parameter of the mbean, and how to make sure the xml specified interceptor have less or more precedence over the code specified one.
What do you think? Is this a bad idea? I think it would make some matters more simple to deal with.
Cheers,
Filippo