我目前正在为hibernate开发各种junit测试。一些Hibernate模型类将不同的模式称为" public"。例如,架构"内部"。现在我必须创建这个模式"内部"在创建表之前。我如何用Hibernate实现这个?
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
答案 0 :(得分:0)