[英]hibernate hsqldb identity column fails to insert new fields
I am using an HSQL database for testing a spring hibernate project and recently introduced an identity field. 我正在使用HSQL数据库来测试Spring Hibernate项目,并且最近引入了一个Identity字段。
The java class looks like (snippet): java类看起来像(片段):
@Entity
@Table(name = "my_table")
public class MyTable {
@Column(name = "sequence_number")
@Id
@GeneratedValue
private Long sequenceNumber;
} }
My sql script to generate the table is given below (snippet): 我的生成表的SQL脚本如下(代码段)所示:
CREATE TABLE my_table (
"sequence_number" BIGINT GENERATED BY DEFAULT AS IDENTITY,
PRIMARY KEY("sequence_number")
);
When I try to add values to the datebase the sql (via show_sql) is: 当我尝试将值添加到日期库时,sql(通过show_sql)为:
insert into my_table (sequence_number) values (default)
I get an exeption stack trace with as key indicators: 我得到了exeption堆栈跟踪,并将其作为关键指标:
org.hibernate.exception.SQLGrammarException: could not prepare statement
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: SEQUENCE_NUMBER
My suspicion is that HSQLDB does not like the default
SQL keyword and would like to see null
instead. 我的怀疑是HSQLDB不喜欢default
SQL关键字,而是希望看到null
。 Is there anyway to get this behaviour through hibernate? 反正有通过休眠进入此行为?
Otherwise, is there a way to get this code to work? 否则,是否有办法使此代码正常工作?
I am using hibernate 4.2.8 and HSQLDb 2.3.2. 我正在使用hibernate 4.2.8和HSQLDb 2.3.2。
The problem is the quotes in the sql. 问题是sql中的引号。 This makes the column names case-sensitive in hsqldb. 这使得hsqldb中的列名区分大小写。 hibernate tries to find a name with ALL-CAPS. 休眠尝试使用ALL-CAPS查找名称。
Changing the ddl in: 在以下位置更改ddl:
CREATE TABLE my_table (
sequence_number BIGINT GENERATED BY DEFAULT AS IDENTITY,
PRIMARY KEY(sequence_number) );
solved the issue. 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.