Search in sources :

Example 1 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate3.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 2 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate3.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)

Aggregations

Properties (java.util.Properties)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 IOException (java.io.IOException)1 Bean (org.springframework.context.annotation.Bean)1 LocalSessionFactoryBean (org.springframework.orm.hibernate3.LocalSessionFactoryBean)1 LocalSessionFactoryBean (org.springframework.orm.hibernate4.LocalSessionFactoryBean)1