[ http://jira.jboss.com/jira/browse/HIBERNATE-6?page=comments#action_12316744 ] Steve Ebersole commented on HIBERNATE-6: ----------------------------------------
Sure, just use the SessionFactoryInterceptor managed attribute on the org.jboss.hibernate.jmx.Hibernate mbean. > HibernateContext Interceptor > ---------------------------- > > Key: HIBERNATE-6 > URL: http://jira.jboss.com/jira/browse/HIBERNATE-6 > Project: Hibernate > Type: Feature Request > Environment: All > Reporter: JesÃs MarÃn > Assignee: Gavin King > > > is there a way to assign an Interceptor to a HibernateContext? > I suppose that overloading getSession, getunmanagedSession and > generateSession is worth the effort. Like this: > public static Session getUnmanagedSession(String name, Interceptor > interceptor) throws HibernateException, IllegalStateException > { > final Session managedSession = lookupSession(name); > if (managedSession == null) > { > throw new IllegalStateException("No managed sessions found for > current context"); > } > return managedSession.getSessionFactory().openSession( > managedSession.connection(), interceptor ); > } > public static Session getSession(String name) > { > return getSession(name, null); > } > public static Session getSession(String name, Interceptor interceptor) > { > try > { > // Determine whether a session is already bound to the current > transaction. > // If so, return that session; otherwise generate a new session, > bind, and > // return it > Session currentSession = lookupSession(name); > if (currentSession == null) > { > currentSession = generateSession(name, interceptor); > prepareSession(name, currentSession); > bind(name, currentSession); > } > return currentSession; > } > catch(HibernateException e) > { > throw new NestedRuntimeException("Could not recover session", e); > } > } > private static Session generateSession(String name, Interceptor > interceptor) throws HibernateException > { > // Make sure there is an ongoing transaction prior to generating > // a session in order to provide a usefull error message... > checkTransactionStatus(); > SessionFactory factory = locateSessionFactory(name); > if (interceptor == null) { > return factory.openSession(); > } else { > return factory.openSession(interceptor); > } > } > Perhaps there is a better way to chain an interceptor into a SessionFactory > using the current HibernateContext and I do not know how? -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ JBoss-Development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jboss-development
