简体   繁体   中英

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.

The java class looks like (snippet):

@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):

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:

insert into my_table (sequence_number) values (default)

I get an exeption stack trace with as key indicators:

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. 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.

The problem is the quotes in the sql. This makes the column names case-sensitive in hsqldb. hibernate tries to find a name with ALL-CAPS.

Changing the ddl in:

CREATE TABLE my_table (
    sequence_number BIGINT GENERATED BY DEFAULT AS IDENTITY,
    PRIMARY KEY(sequence_number) );

solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM