本文介绍了Hsqldb/H2中的单元测试的SequenceGenerator问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾尝试同时使用Hsqldb和H2进行单元测试,但是遇到了序列生成器的问题.字段声明看起来像这样.
I have tried using both Hsqldb and H2 for unit testing but facing problem with sequence generators. Field declaration looks like this.
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="keyword_seq")
@SequenceGenerator(name="keyword_seq",sequenceName="KEYWORD_ID_SEQ", allocationSize=1)
@Column(name="IM_KEYWORD_ID")
private Long keywordId;
当我尝试使用以下配置在Hsqldb中测试此表中的简单插入时,会给出错误
When I try to test simple insert in this table in Hsqldb with following configuration, it gives error
<prop key="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</prop>
<prop key="hibernate.connection.url">jdbc:hsqldb:mem:testdb;sql.syntax_ora=true</prop>
错误:
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: KEYWORD_ID_SEQ.NEXTVAL
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
使用H2:
<prop key="hibernate.connection.driver_class">org.h2.Driver</prop>
<prop key="hibernate.connection.url">jdbc:h2:~/test</prop>
错误是:
Hibernate: select KEYWORD_ID_SEQ.nextval from dual
3085 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 42001, SQLState: 42001
3088 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Syntax error in SQL statement "SELECT KEYWORD_ID_SEQ.NEXTVAL FROM[*] DUAL "; expected "identifier"; SQL statement:
任何想法,如何解决?
推荐答案
我认为方言设置有误.您可以检查休眠配置吗?
I think the dialect is set wrongly. Can you check your hibernate configuration.
这篇关于Hsqldb/H2中的单元测试的SequenceGenerator问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!