使用HSQL进行Hibernate - 不使用hbm2ddl创建表

时间:2014-07-31 09:09:18

标签: java hibernate hsqldb hbm2ddl

我尝试使用HSQLDB(内存模式)运行数据库测试,但hbm2ddl不会创建结构。它表现得好像使用了错误的SQL方言,但日志显示方言已正确设置:

HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
HHH000412: Hibernate Core {4.3.1.Final}
HHH000206: hibernate.properties not found
HHH000021: Bytecode provider name : javassist
Creating new JDBC DriverManager Connection to [jdbc:hsqldb:mem:sample]
HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
HHH000399: Using default transaction strategy (direct JDBC transactions)
HHH000397: Using ASTQueryTranslatorFactory
HV000001: Hibernate Validator 5.1.0.Final
HSEARCH000034: Hibernate Search 4.5.0.Final
HHH000227: Running hbm2ddl schema export
HHH000389: Unsuccessful: create table .dictionary (id bigint generated by default as identity (start with 1), created_on timestamp not null, status varchar(255) not null, updated_on timestamp not null, version_created_by varchar(250), description varchar(250) not null, key varchar(100) not null, scope varchar(100), parent_id bigint, primary key (id))
ERROR o.h.tool.hbm2ddl.SchemaExport - unexpected token: TABLE : line: 2

稍后,在测试中构建其他SQL语句时,Hibernate会发出非常幽默的异常,例如:

java.sql.SQLSyntaxErrorException: unexpected token: FROM required: FROM

我真的不知道导致这种行为的原因,尤其是该日志确认SQL方言与使用的数据库匹配。

1 个答案:

答案 0 :(得分:1)

事实证明,在无模式数据库中(就像HSQL内存中),您可能无法设置Hibernate属性

<prop key="hibernate.default_schema">${hibernate.default_schema}</prop>

以任何方式(将其留空作为设置)。

我的设置是为了生产和测试而创建的,属性hibernate.default_schema被设置为模式名称,或者在相应的环境中保留为空。

感谢有助于我走上正轨的提示。

相关问题