我正在使用old-school ddlutils lib在hsql中创建一个架构,并且看到了这个错误。这很奇怪,因为主键只创建一次。
org.apache.ddlutils.DatabaseOperationException: Error while executing SQL -- -----------------------------------------------------------------------
-- musician
-- -----------------------------------------------------------------------
CREATE TABLE musician
(
id INTEGER IDENTITY,
name VARCHAR(2147483647),
PRIMARY KEY (id)
)
at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
at org.apache.ddlutils.platform.PlatformImplBase.createTables(PlatformImplBase.java:424)
at org.apache.ddlutils.platform.PlatformImplBase.createTables(PlatformImplBase.java:409)
at my.data.SchemaSync.applySchema(SchemaSync.java:104)
at my.data.SchemaSync.start(SchemaSync.java:42)
at my.deploy.BaseEnvironment$1.run(BaseEnvironment.java:38)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLSyntaxErrorException: primary key already exist
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
... 6 more
Caused by: org.hsqldb.HsqlException: primary key already exist
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserTable.readConstraint(Unknown Source)
at org.hsqldb.ParserTable.readTableContentsSource(Unknown Source)
at org.hsqldb.ParserTable.compileCreateTableBody(Unknown Source)
at org.hsqldb.ParserTable.compileCreateTable(Unknown Source)
at org.hsqldb.ParserDDL.compileCreate(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 9 more
答案 0 :(得分:2)
IDENTITY的简单使用意味着生成了主键。最好使用此SQL标准表单:
CREATE TABLE musician
(
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
name VARCHAR(2147483647),
PRIMARY KEY (id)
)
版本2.3.4支持导致错误的语法