Java – sequencegenerator problem for unit testing in HSQLDB / H2
•
Java
I've tried to use HSQLDB and H2 for unit testing, but I'm facing the problem of sequence generator The field declaration is as follows
@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;
It gives an error when I try to test a simple insert in this table in HSQLDB with the following configuration
<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)
Use H2:
<prop key="hibernate.connection.driver_class">org.h2.Driver</prop> <prop key="hibernate.connection.url">jdbc:h2:~/test</prop>
The 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 problem?
Solution
I think the dialect setting is wrong Can you check your sleep configuration?
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码