Search in sources :

Example 1 with AnnotationSessionFactoryBean

use of org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean in project rhino by PLOS.

the class RhinoConfiguration method sessionFactory.

@Bean
public AnnotationSessionFactoryBean sessionFactory(DataSource hibernateDataSource) throws IOException {
    // May be switched to true in a dev environment to log SQL code generated by Hibernate.
    // Could be replaced with environmental config if needed.
    final boolean hibernateIsInDebugMode = false;
    AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean();
    bean.setDataSource(hibernateDataSource);
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.dialect", org.hibernate.dialect.MySQLDialect.class.getName());
    hibernateProperties.setProperty("hibernate.show_sql", Boolean.toString(hibernateIsInDebugMode));
    hibernateProperties.setProperty("hibernate.format_sql", Boolean.toString(hibernateIsInDebugMode));
    bean.setHibernateProperties(hibernateProperties);
    bean.setPackagesToScan("org.ambraproject.rhino.model");
    return bean;
}
Also used : AnnotationSessionFactoryBean(org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean) Properties(java.util.Properties) AnnotationSessionFactoryBean(org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with AnnotationSessionFactoryBean

use of org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean in project simple-java by angryziber.

the class HibernatePhotoSpotRepositoryIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    dataSource = new DriverManagerDataSource("jdbc:h2:mem:hibernate;DB_CLOSE_DELAY=-1", "sa", "sa");
    System.setProperty("hibernate.dialect", H2Dialect.class.getName());
    System.setProperty("hibernate.hbm2ddl.auto", "create-drop");
    AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    sessionFactory.setAnnotatedClasses(new Class[] { PhotoSpot.class });
    sessionFactory.afterPropertiesSet();
    repo.hibernate = new HibernateTemplate(sessionFactory.getObject());
}
Also used : H2Dialect(org.hibernate.dialect.H2Dialect) AnnotationSessionFactoryBean(org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) Before(org.junit.Before)

Aggregations

AnnotationSessionFactoryBean (org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean)2 Properties (java.util.Properties)1 H2Dialect (org.hibernate.dialect.H2Dialect)1 Before (org.junit.Before)1 Bean (org.springframework.context.annotation.Bean)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1