SequenceGenerator problem with unit testing in Hsqldb/H2

核能气质少年 提交于 2019-12-23 18:24:59

问题


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;

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>

Error :

   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)

With H2:

<prop key="hibernate.connection.driver_class">org.h2.Driver</prop>
<prop key="hibernate.connection.url">jdbc:h2:~/test</prop>

Error is :

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:

Any idea, how to solve this?


回答1:


I think the dialect is set wrongly. Can you check your hibernate configuration.



来源:https://stackoverflow.com/questions/7473131/sequencegenerator-problem-with-unit-testing-in-hsqldb-h2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!