自动休眠架构创建无法正常工作(junit + spring)

时间:2016-02-09 13:24:29

标签: spring hibernate junit hbm2ddl

我正在使用以下spring配置运行JUnit测试用例。自动模式创建没有发生。

@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;
    }
}

我已经调试以确保实际上跳过了架构创建。

知道为什么可能会跳过架构创建吗?

1 个答案:

答案 0 :(得分:1)

尝试使用hibernate.hbm2ddl.auto代替hbm2ddl..auto