Search in sources :

Example 16 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project druid by alibaba.

the class HibernateCRUDTest method setUp.

@Override
public void setUp() throws Exception {
    /*init dataSource*/
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:h2:file:~/.h2/HibernateCRUDTest;AUTO_SERVER=TRUE");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    dataSource.setDefaultAutoCommit(false);
    dataSource.setFilters("log4j");
    /*init sessionFactory*/
    LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    Properties prop = new Properties();
    prop.put("hibernate.show_sql", "true");
    // prop.put("hibernate.format_sql", "true");
    prop.put("hibernate.hbm2ddl.auto", "create");
    prop.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    factoryBean.setHibernateProperties(prop);
    factoryBean.setAnnotatedClasses(new Class<?>[] { Sample.class });
    try {
        factoryBean.afterPropertiesSet();
    } catch (IOException e) {
        e.printStackTrace();
    }
    sessionFactory = factoryBean.getObject();
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) IOException(java.io.IOException) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 17 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project rhino by PLOS.

the class TestConfiguration method sessionFactory.

@Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) throws IOException {
    LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setSchemaUpdate(true);
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    bean.setHibernateProperties(hibernateProperties);
    return bean;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate3.LocalSessionFactoryBean) Properties(java.util.Properties) LocalSessionFactoryBean(org.springframework.orm.hibernate3.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 18 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project Synergy by Meggot.

the class SQLDatabaseConfiguration method sessionFactory.

@Bean(name = "sessionFactory")
public SessionFactory sessionFactory() {
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource());
    sessionFactory.setPackagesToScan("accountDao", "projectDao");
    sessionFactory.setHibernateProperties(hibernateProperties());
    return sessionFactory.getObject();
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean)

Example 19 with LocalSessionFactoryBean

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

the class Cause3PersistenceConfig method sessionFactory.

@Bean
public LocalSessionFactoryBean sessionFactory() {
    final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(restDataSource());
    sessionFactory.setHibernateProperties(hibernateProperties());
    // sessionFactory.setPackagesToScan(new String[] { "org.baeldung.ex.mappingexception.cause2.persistence.model" });
    sessionFactory.setAnnotatedClasses(new Class[] { Foo.class });
    return sessionFactory;
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean)

Example 20 with LocalSessionFactoryBean

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

the class Cause5NonTransientConfig method sessionFactory.

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

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