Best way to create schema in embedded HSQL database

China☆狼群 提交于 2019-12-05 03:26:25

By default HSQL creates a schema called PUBLIC. source: HSQL documentation

Seeing as the schema name is never seen in the tests (named queries/entity manager to do the interactions) you can change the hibernate properties to use this PUBLIC schema

<properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    <property name="hibernate.default_schema" value="PUBLIC"/>
    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>

OR
just leave out the default_schema from the properties list and it uses PUBLIC anyway

<properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>

You can use this code in your Base Testing class, and call it using @BeforeClass annotation (for Junit). I do it like this.

    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    builder = builder.setType(EmbeddedDatabaseType.HSQL).addScript(
            "createSchema.sql");
    builder.setName("MyDatabase");
    EmbeddedDatabase db = builder.build();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!