I am configuring an h2 test database for our oracle production database. All tables are of the schema xxx
. My datasource is defined as below:
public DataSource dataSource() {
JdbcDataSource ds = new JdbcDataSource();
ds.setUrl("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=Oracle;TRACE_LEVEL_SYSTEM_OUT=2;INIT=CREATE SCHEMA IF NOT EXISTS xxx;SCHEMA=xxx");
ds.setUser("xxx");
ds.setPassword("xxx");
return ds;
}
With SCHEMA=xxx
, I get an error: Caused by: org.h2.jdbc.JdbcSQLException: Schema "xxx" not found; SQL statement: SET SCHEMA xxx [90079-186]
Without SCHEMA=xxx
, I get errors whenever Hibernate attempts to run a query with a join because it does not prepend the schema to the table name. It does this in production with our oracle database though.
Edit: To provide some more insight, I am populating my db from creation scripts that are also used in production:
@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
final DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setDatabasePopulator(databasePopulator());
return initializer;
}
private DatabasePopulator databasePopulator() {
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.setSeparator(";");
populator.setCommentPrefix("--");
populator.addScript(new ClassPathResource("db-schema.sql"));
populator.addScript(new ClassPathResource("db-init-data.sql"));
return populator;
}