Java Code Examples for org.springframework.orm.hibernate5.LocalSessionFactoryBean#setDataSource()
The following examples show how to use
org.springframework.orm.hibernate5.LocalSessionFactoryBean#setDataSource() .
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: HibernateTransactionManagerConfiguration.java From hypersistence-optimizer with Apache License 2.0 | 9 votes |
@Bean public LocalSessionFactoryBean sessionFactory() { LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); localSessionFactoryBean.setDataSource(dataSource()); localSessionFactoryBean.setPackagesToScan(packagesToScan()); localSessionFactoryBean.setHibernateProperties(additionalProperties()); return localSessionFactoryBean; }
Example 2
Source File: InfrastructureConfig.java From Learning-Path-Spring-5-End-to-End-Programming with MIT License | 7 votes |
@Bean public LocalSessionFactoryBean sessionFactory(DataSource dataSource) { LocalSessionFactoryBean sfb = new LocalSessionFactoryBean(); sfb.setDataSource(dataSource); sfb.setPackagesToScan(new String[] { "com.packt.patterninspring.chapter8.bankapp.model" }); Properties props = new Properties(); props.setProperty("dialect", "org.hibernate.dialect.H2Dialect"); sfb.setHibernateProperties(props); return sfb; }
Example 3
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 4
Source File: DatabaseConfig.java From spring-security-jwt-rest-stateless with MIT License | 6 votes |
@Bean(name = "sessionFactory") public LocalSessionFactoryBean hibernate5SessionFactoryBean(){ LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); localSessionFactoryBean.setDataSource(appContext.getBean(HikariDataSource.class)); localSessionFactoryBean.setAnnotatedClasses( AppUser.class ); Properties properties = new Properties(); properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect"); //properties.put("hibernate.current_session_context_class","thread"); properties.put("hibernate.hbm2ddl.auto","update"); localSessionFactoryBean.setHibernateProperties(properties); return localSessionFactoryBean; }
Example 5
Source File: HiberConfig.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Bean("sessionFactory") public LocalSessionFactoryBean localSessionFactory(DataSource dataSource, Properties hibernateProperties) { LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setPackagesToScan(new String[] { "org.packt.hiber.core.model.data" }); sessionFactory.setHibernateProperties(hibernateProperties); return sessionFactory; }
Example 6
Source File: HibernateConfig.java From spring4-hibernate5-example with MIT License | 5 votes |
@Bean public LocalSessionFactoryBean getSessionFactory() { LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(getDataSource()); sessionFactory.setPackagesToScan(new String[] { "com.bytestree.model" }); sessionFactory.setHibernateProperties(getHibernateProperties()); return sessionFactory; }
Example 7
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 8
Source File: HibernateTransactionManagerConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 5 votes |
@Bean public LocalSessionFactoryBean sessionFactory() { LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setDataSource(dataSource()); sessionFactoryBean.setPackagesToScan(packagesToScan()); sessionFactoryBean.setHibernateProperties(additionalProperties()); sessionFactoryBean.setHibernateIntegrators(new ClassImportIntegrator(Arrays.asList(PostDTO.class))); return sessionFactoryBean; }
Example 9
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(); }