在嵌入式HSQL数据库中创建模式的最佳方法 [英] Best way to create schema in embedded HSQL database
问题描述
我正在使用以下设置在嵌入式数据库中创建模式,然后再运行我的测试。
在我的应用程序上下文中
< jdbc:embedded-database id =dataSourcetype =HSQL>
< jdbc:script location =classpath:createSchema.sql/>
< / jdbc:embedded-database>
createSchema.sql
create schema ST_TEST AUTHORIZATION DBA;
hibernate属性
<性状>
< property name =hibernate.dialectvalue =org.hibernate.dialect.HSQLDialect/>
< property name =hibernate.default_schemavalue =ST_TEST/>
< property name =hibernate.hbm2ddl.autovalue =create-drop/>
< property name =hibernate.show_sqlvalue =true/>
< property name =hibernate.use_sql_commentsvalue =true/>
< property name =hibernate.cache.use_second_level_cachevalue =false/>
< / properties>
我的问题是这是做到这一点的最佳方式。或者我可以在我的属性中使用不同的模式名称?或者在jdbc:embedded-database元素中设置模式名称。默认情况下,HSQL创建一个名为PUBLIC的模式。
来源:HSQL文档在测试中从未看到模式名称(命名查询/实体管理器进行交互),您可以将hibernate属性更改为使用此PUBLIC模式
<性状>
< property name =hibernate.dialectvalue =org.hibernate.dialect.HSQLDialect/>
< property name =hibernate.default_schemavalue =PUBLIC/>
< property name =hibernate.hbm2ddl.autovalue =create-drop/>
< / properties>
或
只需从属性列表中省略default_schema,并使用PUBLIC无论如何
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.HSQLDialect/>
< property name =hibernate.hbm2ddl.autovalue =create-drop/>
< / properties>
I'm currently using the following setup to create a schema in an embedded database before running my tests against it
In my application context
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:createSchema.sql" />
</jdbc:embedded-database>
createSchema.sql
create schema ST_TEST AUTHORIZATION DBA;
hibernate properties
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.default_schema" value="ST_TEST"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
</properties>
My question is is this the best way to do this. Or can i use a different schema name in my properties? or set the schema name in the jdbc:embedded-database element
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>
这篇关于在嵌入式HSQL数据库中创建模式的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!