S V
S V

Reputation: 580

Automatic hibernate schema creation not working (junit+spring)

I am running a JUnit test case with the following spring config. THe automatic schema creation is not happening.

@Configuration
public class DatabaseConfiguration {

    @Bean
    DataSource dataSource() {
        BasicDataSource ret = new BasicDataSource();
        ret.setDriverClassName("com.mysql.jdbc.Driver");
        ret.setUrl("jdbc:mysql://localhost:3306/mydb");
        ret.setUsername("root");
        ret.setPassword("root");
        return ret;
    }


    @Bean
    SessionFactory sessionFactoryBean(DataSource dataSource) {
        LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(
                dataSource);
        sessionBuilder.scanPackages("com.mypackage.domain");
        sessionBuilder.addProperties(getHibernateProperties());
        return sessionBuilder.buildSessionFactory();
    }

    private Properties getHibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.show_sql", "true");
        properties.put("hbm2ddl.auto", "create");
        properties.put("hibernate.dialect",
                "org.hibernate.dialect.MySQLDialect");
        return properties;
    }

    @Bean
    HibernateTransactionManager transactionManager(SessionFactory lsfb) {
        HibernateTransactionManager mgr = new HibernateTransactionManager();
        mgr.setSessionFactory(lsfb);
        return mgr;
    }
}

I have debugged to make sure that the schema creation is actually getting skipped.

Any idea why the schema creation might get skipped?

Upvotes: 0

Views: 121

Answers (1)

Try with hibernate.hbm2ddl.auto instead of hbm2ddl..auto

Upvotes: 1

Related Questions