protected SessionFactory createSessionFactory(DbDialect dialect) {
SessionFactory result = getHibernateSessionFactory();
if (result != null) {
return result;
}
LocalSessionFactoryBean factory = getHibernateFactoryBean();
if (factory == null) {
String[] files = createHibernateFiles();
if (files.length == 0) {
return null; // Hibernate not required
}
factory = new LocalSessionFactoryBean();
factory.setMappingResources(files);
factory.setDataSource(getDataSource());
Properties props = new Properties();
props.setProperty("hibernate.dialect", dialect.getHibernateDialect().getClass().getName());
props.setProperty("hibernate.show_sql", String.valueOf(isHibernateShowSql()));
props.setProperty("hibernate.connection.release_mode", "on_close");
if (isAllowHibernateThreadBoundSession()) {
props.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
props.setProperty(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JDBCTransactionFactory");
}
factory.setHibernateProperties(props);
factory.setLobHandler(dialect.getLobHandler());
}
try {
factory.afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return factory.getObject();
}