【发布时间】:2014-12-05 00:06:21
【问题描述】:
所以我很惊讶这个问题的答案不容易找到,但我想在数据库生成后插入一些数据。
RootConfig.java:
...
@Bean
public DataSource dataSource() throws SQLException {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL)
.setName("db")
.addScript("setup_data.sql")
.continueOnError(true)
.build();
}
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setShowSql(true);
vendorAdapter.setDatabase(Database.HSQL);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
Map<String, Object> props = new HashMap<>();
props.put("eclipselink.weaving", "false");
props.put("eclipselink.target-database", HSQLPlatform.class.getName());
props.put("eclipselink.cache.shared.default", "false");
props.put("eclipselink.logging.parameters", "true");
props.put("eclipselink.logging.level", "FINEST");
props.put("eclipselink.logging.level.sql", "FINEST");
props.put("eclipselink.logging.level.cache", "FINEST");
factory.setJpaPropertyMap(props);
factory.setPackagesToScan("com.citysports.leaguesports.domain");
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
return factory.getObject();
}
...
我正在生成 ddl,但是当我 addScript('setup_data.sql') 时出现错误,因为它尚未生成表。如何在 ddl 生成后运行脚本?
【问题讨论】:
标签: java spring hibernate jpa eclipselink