0
私は現在、hibernate用のさまざまなjunitテストを開発中です。いくつかのHibernateモデルクラスは、異なるスキーマを "public"として参照します。たとえば、スキーマ "internal"です。今は、テーブルが作成される前にこのスキーマを「内部的に」作成する必要があります。これをHibernateでどのように実装するのですか?Hibernate:テーブルの前にpsqlスキーマを作成します。
Test.java
@Before
public void setUp() throws IOException, URISyntaxException, InterruptedException {
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(Table.class);
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configuration.setProperty("hibernate.hbm2ddl.auto", "create");
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
this.sf = configuration.buildSessionFactory(serviceRegistry);
this.injector = Guice.createInjector(new CoreModule());
this.injector.injectMembers(this);
Key<SimpleScope> simpleScopeKey = Key.get(SimpleScope.class, Names.named("scriptingScope"));
this.scope = this.injector.getInstance(simpleScopeKey);
}
@After
public void tearDown() throws Exception {
this.sf.close();
}
Table.java
@Entity
@Table(schema = "internal", name = "table")
public class Table {
@Id
private Long id;
@Column(name = "name")
private String name;
}
エラー
Schema "RIS" not found; SQL statement:
create table internal.table (id bigint not null, name varchar(255), primary key (id)) [90079-193]
Feb 13, 2017 10:52:20 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
たぶん、この答えは助けることができますあなた** http:// s tackoverflow.com/questions/23305778/h2-database-unit-test-across-multiple-schema** – Massimo