如何在spring jpa中创建表

时间:2015-09-04 13:47:40

标签: java spring spring-boot spring-data

我希望如果数据库中不存在表,那么它们应该自动创建,但它们不应该覆盖现有数据或删除表。

我在属性文件

中使用过
spring.jpa.properties.hibernate.hbm2ddl.auto=update 

我试过了#34;没有"选项也是。

我的 entityManager

LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setDataSource(dataSource());

    factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
    factoryBean.setPackagesToScan(R.Blueberry_PACKAGE);
    factoryBean.setPersistenceUnitName("blueberryPersistenceUnit");
    Properties jpaProperties = new Properties();
    factoryBean.setJpaProperties(jpaProperties);
    factoryBean.afterPropertiesSet();

    return factoryBean.getObject();

jpaVendor

@Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
        jpaVendorAdapter.setShowSql(true);
        jpaVendorAdapter.setGenerateDdl(true);
        jpaVendorAdapter.setDatabase(Database.MYSQL);
        return jpaVendorAdapter;
    }

0 个答案:

没有答案