@Bean(name = "sessionFactory") public SessionFactory sessionFactory() throws IOException { LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setDataSource(dataSource()); sessionFactoryBean.setPackagesToScan("com.avol.domain"); sessionFactoryBean.setAnnotatedPackages("com.avol.domain"); sessionFactoryBean.setHibernateProperties(getHibernateProperties()); sessionFactoryBean.afterPropertiesSet(); return sessionFactoryBean.getObject(); }
@Bean public SessionFactory sessionFactory( DataSource dataSource, @Value("${hibernate.packagesToScan}") String packagesToScan, @Qualifier("hibernateProperties") Properties properties) throws Exception { LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setDataSource(dataSource); sessionFactoryBean.setPackagesToScan(packagesToScan); sessionFactoryBean.setHibernateProperties(properties); sessionFactoryBean.afterPropertiesSet(); return sessionFactoryBean.getObject(); }
@Override public void afterPropertiesSet() throws IOException { super.afterPropertiesSet(); for (Map.Entry<String, DataSource> entry : dataSourceMap.entrySet()) { Connection connection = null; try { connection = entry.getValue().getConnection(); SchemaExport export = new SchemaExport(getConfiguration(), connection); export.setOutputFile(entry.getKey() + "-schema.sql"); export.setDelimiter(";"); // this must be changed in order to support create, drop, validate etc // export.execute(true, true, false, true); } catch (SQLException e) { throw new RuntimeException(e); } } }