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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations