List of usage examples for org.hibernate.cfg Configuration getEntityTuplizerFactory
public EntityTuplizerFactory getEntityTuplizerFactory()
From source file:gr.interamerican.bo2.impl.open.hibernate.HibernateConfigurations.java
License:Open Source License
/** * Creates a SessionFactory.// w w w.j a v a2 s.c o m * * @param pathToCfg * Path to the hibernate configuration file. * @param dbSchema * Db schema. * @param sessionInterceptor * Hibernate session interceptor. * @param hibernateMappingsPath * Path to file that lists files indexing hbm files this session factory * should be configured with * * @return Returns the session factory. * * @throws InitializationException * If the creation of the SessionFactory fails. */ @SuppressWarnings("nls") static SessionFactory createSessionFactory(String pathToCfg, String dbSchema, String sessionInterceptor, String hibernateMappingsPath) throws InitializationException { try { Configuration conf = new Configuration(); Interceptor interceptor = getInterceptor(sessionInterceptor); if (interceptor != null) { conf.setInterceptor(interceptor); } conf.setProperty(SCHEMA_PROPERTY, dbSchema); List<String> hbms = getHibernateMappingsIfAvailable(hibernateMappingsPath); for (String entityMapping : hbms) { LOGGER.debug("Adding " + entityMapping + " to the session factory configuration."); conf.addResource(entityMapping); } conf.configure(pathToCfg); conf.getEntityTuplizerFactory().registerDefaultTuplizerClass(EntityMode.POJO, Bo2PojoEntityTuplizer.class); SessionFactory sessionFactory = conf.buildSessionFactory(); ((SessionFactoryImpl) sessionFactory).registerEntityNameResolver(Bo2EntityNameResolver.INSTANCE, EntityMode.POJO); sessionFactory.getStatistics().setStatisticsEnabled(true); return sessionFactory; } catch (HibernateException e) { throw new InitializationException(e); } }