Java Code Examples for org.springframework.orm.hibernate5.LocalSessionFactoryBean#afterPropertiesSet()
The following examples show how to use
org.springframework.orm.hibernate5.LocalSessionFactoryBean#afterPropertiesSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionFactoryImpl.java From tephra with MIT License | 6 votes |
private SessionFactory createSessionFactory(Properties properties, DataSource dataSource, String[] packagesToScan) { if (dataSource == null) throw new NullPointerException("数据源不存在,无法初始化Hibernate环境!"); LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setHibernateProperties(properties); sessionFactoryBean.setDataSource(dataSource); sessionFactoryBean.setPackagesToScan(packagesToScan); try { sessionFactoryBean.afterPropertiesSet(); return sessionFactoryBean.getObject(); } catch (IOException e) { logger.warn(e, "初始化Hibernate环境[{}]时发生异常!", converter.toString(packagesToScan)); return null; } }
Example 2
Source File: TransactionManagerHolder.java From framework with Apache License 2.0 | 5 votes |
/** * Description: 获取session 工厂 <br> * * @author 王伟<br> * @taskId <br> * @return <br> * @throws IOException */ public static SessionFactory getSessionFactory() { synchronized (sessionFactoryHolder) { String dbCode = DynamicDataSourceManager.getDataSourceCode(); SessionFactory sessionFactory = sessionFactoryHolder.get(dbCode); if (sessionFactory == null) { DataSource dataSource = DataSourceUtil.getDataSource(dbCode); Assert.notNull(dataSource, ErrorCodeDef.DB_DATASOURCE_NOT_SET, dbCode); LocalSessionFactoryBean bean = new LocalSessionFactoryBean(); bean.setDataSource(dataSource); Map<String, String> map = PropertyHolder.getProperties(); Properties properties = new Properties(); int prefixLength = dbCode.length() + 1; String prefix = dbCode + ".hibernate"; for (Entry<String, String> entry : map.entrySet()) { if (entry.getKey().startsWith(prefix)) { properties.setProperty(entry.getKey().substring(prefixLength, entry.getKey().length()), entry.getValue()); } } bean.setHibernateProperties(properties); bean.setPackagesToScan(getBasePackage()); try { bean.afterPropertiesSet(); } catch (IOException e) { throw new InitializationException(e); } sessionFactory = bean.getObject(); sessionFactoryHolder.put(dbCode, sessionFactory); } return sessionFactory; } }
Example 3
Source File: Config.java From spring-data-jpa-datatables with Apache License 2.0 | 5 votes |
@Bean public SessionFactory entityManagerFactory(DataSource dataSource) throws Exception { LocalSessionFactoryBean factory = new LocalSessionFactoryBean(); factory.setPackagesToScan(Config.class.getPackage().getName()); factory.setDataSource(dataSource); factory.afterPropertiesSet(); return factory.getObject(); }