我正在开发spring boot 2应用程序并尝试通过配置hikari数据源和spring Jpa来建立与postgresql数据库的连接。
我成功了,我正在使用它,如果不存在hibernate.hbm2ddl.auto,update它会创建表,但唯一的问题是当模式不存在时它会抛出异常
错误
GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
Caused by: org.postgresql.util.PSQLException: ERROR: schema "test_schema" does not exist
我通过配置类手动配置了所有内容
配置类
@Bean
@Primary
public HikariDataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(databaseUrl);
config.setUsername(username);
config.setPassword(password);
config.setDriverClassName(driverClassName);
config.setConnectionTimeout(connectionTimeout);
config.setIdleTimeout(idleTimeout);
config.setMaximumPoolSize(maxpoolSize);
config.setMaxLifetime(maxLifeTime);
config.setMinimumIdle(minIdleConnections);
//config.setPoolName(poolName);
return new HikariDataSource(config);
}
@Bean
public Properties additionalProps() {
Properties jpaProps = new Properties();
jpaProps.put(hbDialect, "org.hibernate.dialect.PostgreSQLDialect");
jpaProps.put(autoDDL, "update");
jpaProps.put(showSql, true);
jpaProps.put(formatSql, true);
return jpaProps;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setDataSource(dataSource());
factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factory.setPackagesToScan("com.target.storetaskcount.entity");
factory.setJpaProperties(additionalProps());
return factory;
}
如果不存在,我将如何创建模式?
我在这里看到了一个类似的问题,并尝试了所有到目前为止都没有运气的类似问题(我不想使用 flyway db)
这是文档hibernate-doc,但不清楚如何添加此属性来创建模式javax.persistence.schema-generation.database.action
宝慕林4294392
斯蒂芬大帝
慕田峪7331174
相关分类