2017-02-13 35 views
0

我目前正在開發各種針對休眠的junit測試。一些Hibernate模型類將不同的模式稱爲「public」。例如,模式「內部」。現在我必須在創建表之前「內部」創建這個模式。我如何得到這與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 
+0

也許這個回答可以幫助你** http:// s tackoverflow.com/questions/23305778/h2-database-unit-test-across-multiple-schema** – Massimo

回答