// We could also let Hibernate bind it to JNDI: // configuration.configure().buildSessionFactory() } catch (Throwable ex) { // We have to catch Throwable, otherwise we will miss // NoClassDefFoundError and other subclasses of Error log.error("Building SessionFactory failed.", ex); throw new ExceptionInInitializerError(ex); } }
/* * Returns the SessionFactory used for this static class. * * @return SessionFactory */ public static SessionFactory getSessionFactory() { /* Instead of a static variable, use JNDI: SessionFactory sessions = null; try { Context ctx = new InitialContext(); String jndiName = "java:hibernate/HibernateFactory"; sessions = (SessionFactory)ctx.lookup(jndiName); } catch (NamingException ex) { throw new InfrastructureException(ex); } return sessions; */ return sessionFactory; }
/* * Returns the original Hibernate configuration. * * @return Configuration */ public static Configuration getConfiguration() { return configuration; }
/* * Register a Hibernate interceptor with the current thread. * 在当前线程中注册一个Hibernate拦截机 *
* Every Session opened is opened with this interceptor after * registration. Has no effect if the current Session of the * thread is already open, effective on next close()/getSession(). */ public static void registerInterceptor(Interceptor interceptor) { threadInterceptor.set(interceptor); }
// We could also let Hibernate bind it to JNDI: // configuration.configure().buildSessionFactory() } catch (Throwable ex) { // We have to catch Throwable, otherwise we will miss // NoClassDefFoundError and other subclasses of Error log.error("Building SessionFactory failed.", ex); throw new ExceptionInInitializerError(ex); } }
/* * Returns the SessionFactory used for this static class. * * @return SessionFactory */ public static SessionFactory getSessionFactory() { /* Instead of a static variable, use JNDI: SessionFactory sessions = null; try { Context ctx = new InitialContext(); String jndiName = "java:hibernate/HibernateFactory"; sessions = (SessionFactory)ctx.lookup(jndiName); } catch (NamingException ex) { throw new InfrastructureException(ex); } return sessions; */ return sessionFactory; }
/* * Returns the original Hibernate configuration. * * @return Configuration */ public static Configuration getConfiguration() { return configuration; }
/* * Register a Hibernate interceptor with the current thread. * 在当前线程中注册一个Hibernate拦截机 *
* Every Session opened is opened with this interceptor after * registration. Has no effect if the current Session of the * thread is already open, effective on next close()/getSession(). */ public static void registerInterceptor(Interceptor interceptor) { threadInterceptor.set(interceptor); }
/* * Register a Hibernate interceptor with the current thread. * 在当前线程中注册一个Hibernate拦截机 *
* Every Session opened is opened with this interceptor after * registration. Has no effect if the current Session of the * thread is already open, effective on next close()/getSession(). */ public static void registerInterceptor(Interceptor interceptor) { threadInterceptor.set(interceptor); }
* Every Session opened is opened with this interceptor after * registration. Has no effect if the current Session of the * thread is already open, effective on next close()/getSession(). */ public static void registerInterceptor(Interceptor interceptor) { threadInterceptor.set(interceptor); }