Search in sources :

Example 11 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project tutorials by eugenp.

the class PersistenceConfig method sessionFactory.

@Bean
public LocalSessionFactoryBean sessionFactory() {
    final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(restDataSource());
    sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
    sessionFactory.setHibernateProperties(hibernateProperties());
    return sessionFactory;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean)

Example 12 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project classify-system by anverliedoit.

the class JPAConfig method sessionFactory.

@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource());
    sessionFactory.setHibernateProperties(hibernateProperties());
    sessionFactory.setPackagesToScan("com.remswork.project.alice.model");
    return sessionFactory;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean) DataSourcePropertiesBean(com.remswork.project.alice.bean.DataSourcePropertiesBean) LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean)

Example 13 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project PublicCMS-preview by sanluan.

the class ApplicationConfig method hibernateSessionFactory.

/**
 * Hibernate 会话工厂类
 *
 * @param dataSource
 * @return hibernate session factory
 * @throws PropertyVetoException
 * @throws IOException
 */
@Bean
public FactoryBean<SessionFactory> hibernateSessionFactory(DataSource dataSource) throws PropertyVetoException, IOException {
    LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setPackagesToScan("com.publiccms.entities");
    Properties properties = PropertiesLoaderUtils.loadAllProperties(env.getProperty("cms.hibernate.configFilePath"));
    properties.setProperty("hibernate.search.default.indexBase", getDirPath("/indexes/"));
    MultiTokenizerFactory.setName(env.getProperty("cms.tokenizerFactory"));
    bean.setHibernateProperties(properties);
    return bean;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Properties(java.util.Properties) FactoryBean(org.springframework.beans.factory.FactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 14 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project dhis2-core by dhis2.

the class HibernateConfig method sessionFactory.

@Bean
@DependsOn("flyway")
public LocalSessionFactoryBean sessionFactory(DataSource dataSource, @Qualifier("hibernateConfigurationProvider") HibernateConfigurationProvider hibernateConfigurationProvider) {
    Objects.requireNonNull(dataSource);
    Objects.requireNonNull(hibernateConfigurationProvider);
    Properties hibernateProperties = hibernateConfigurationProvider.getConfiguration().getProperties();
    Objects.requireNonNull(hibernateProperties);
    List<Resource> jarResources = hibernateConfigurationProvider.getJarResources();
    List<Resource> directoryResources = hibernateConfigurationProvider.getDirectoryResources();
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    sessionFactory.setMappingJarLocations(jarResources.toArray(new Resource[0]));
    sessionFactory.setMappingDirectoryLocations(directoryResources.toArray(new Resource[0]));
    sessionFactory.setAnnotatedClasses(DeletedObject.class);
    sessionFactory.setHibernateProperties(hibernateProperties);
    return sessionFactory;
}
Also used : Resource(org.springframework.core.io.Resource) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Properties(java.util.Properties) DependsOn(org.springframework.context.annotation.DependsOn) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project midpoint by Evolveum.

the class SqlRepositoryBeanConfig method sessionFactory.

@Bean
@ConditionalOnMissingBean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource, SqlRepositoryConfiguration configuration, MidPointImplicitNamingStrategy midPointImplicitNamingStrategy, MidPointPhysicalNamingStrategy midPointPhysicalNamingStrategy, EntityStateInterceptor entityStateInterceptor) {
    LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
    // While dataSource == dataSourceFactory.getDataSource(), we're using dataSource as
    // parameter to assure, that Spring already called the factory method. Explicit is good.
    bean.setDataSource(dataSource);
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.dialect", configuration.getHibernateDialect());
    hibernateProperties.setProperty("hibernate.hbm2ddl.auto", configuration.getHibernateHbm2ddl());
    hibernateProperties.setProperty("hibernate.id.new_generator_mappings", "true");
    hibernateProperties.setProperty("hibernate.jdbc.batch_size", "20");
    hibernateProperties.setProperty("javax.persistence.validation.mode", "none");
    hibernateProperties.setProperty("hibernate.transaction.coordinator_class", "jdbc");
    hibernateProperties.setProperty("hibernate.hql.bulk_id_strategy", "org.hibernate.hql.spi.id.inline.InlineIdsOrClauseBulkIdStrategy");
    bean.setHibernateProperties(hibernateProperties);
    bean.setImplicitNamingStrategy(midPointImplicitNamingStrategy);
    bean.setPhysicalNamingStrategy(midPointPhysicalNamingStrategy);
    bean.setAnnotatedPackages("com.evolveum.midpoint.repo.sql.type");
    bean.setPackagesToScan("com.evolveum.midpoint.repo.sql.data.common", "com.evolveum.midpoint.repo.sql.data.common.any", "com.evolveum.midpoint.repo.sql.data.common.container", "com.evolveum.midpoint.repo.sql.data.common.embedded", "com.evolveum.midpoint.repo.sql.data.common.enums", "com.evolveum.midpoint.repo.sql.data.common.id", "com.evolveum.midpoint.repo.sql.data.common.other", "com.evolveum.midpoint.repo.sql.data.common.type", "com.evolveum.midpoint.repo.sql.data.audit");
    bean.setEntityInterceptor(entityStateInterceptor);
    return bean;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Properties(java.util.Properties) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Bean (org.springframework.context.annotation.Bean)17 LocalSessionFactoryBean (org.springframework.orm.hibernate4.LocalSessionFactoryBean)12 LocalSessionFactoryBean (org.springframework.orm.hibernate5.LocalSessionFactoryBean)7 Properties (java.util.Properties)6 IOException (java.io.IOException)2 Resource (org.springframework.core.io.Resource)2 LocalSessionFactoryBean (org.springframework.orm.hibernate3.LocalSessionFactoryBean)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 SqlRepositoryBeanConfig (com.evolveum.midpoint.repo.sql.SqlRepositoryBeanConfig)1 DataSourcePropertiesBean (com.remswork.project.alice.bean.DataSourcePropertiesBean)1 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)1 FactoryBean (org.springframework.beans.factory.FactoryBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 DependsOn (org.springframework.context.annotation.DependsOn)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1