Ich entwickle derzeit verschiedene Junit-Tests für Hibernate. Einige Hibernate-Modellklassen verweisen auf ein anderes Schema als "public". Zum Beispiel das Schema "intern". Jetzt muss ich dieses Schema "intern" erstellen, bevor die Tabellen erstellt werden. Wie kann ich dies mit Hibernate implementieren?Hibernate: Erstellen psql-Schema vor den Tabellen
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;
}
Fehler
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
Vielleicht kann diese Antwort helfen Sie ** http: // s tackoverflow.com/questions/23305778/h2-database-unit-test-across-multiple-schema**** – Massimo