Issue
In managed environment how to create interceptor for each session. in an un-managed environment, SF.openSession(interceptor) is available. But in managed environment using CMT , sesison is taken using SF.getCurrentSession() method. how to specify interceptor in this case.
there is option to specify interceptor at sesison factory level using new Configuration.configure(" ").setInterceptor(interceptor).buildSessionFactory() . but for audit need to create new instance of interceptor for each sesison. In interceptor value for each transaction lile userId, code etc need to be set. these values will be used in interceptor call back methods.
Is there a way out.
Hibernate version: 3.0.5
Mapping documents:
<property name="hibernate.session_factory_name">HibernateSessionFactory</property>
<property name="connection.datasource">jdbc/p4fDB</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
Code :
public static Session getSession(String jndiName, Interceptor interceptor){
Session session = null;
SessionFactory sessionFactory = getSessionFactory(jndiName);
if(sessionFactory != null){
// this code doesn't work properly. like for saving an entity, session.save() persist but session.saveOrupdate() doesn't. also not sure if this session is aware of JTA
session = sessionFactory.openSession(interceptor);
}
return session;
}
|