Derby:批量导入未设置AUTO_INCREMENT

时间:2013-04-06 09:44:52

标签: java import jpa-2.0 derby

说我有table生成的Eclipselink

CREATE TABLE "ACCOUNT" ("ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "DTYPE" VARCHAR(31), "EMAIL" VARCHAR(255));

接下来,我将从文件导入批量,其中包含:

1,"admin_","myemail@domain.com"
2,"user_","anotheremail@domain.com"
3,"user_","yetanotherone@domain.com"

导入成功,使用ij tool中的ApacheSYSCS_UTIL.SYCS_IMPORT_TABLE()

接下来,我将通过JPA2创建一个用户。这导致:

Caused by: org.apache.derby.client.am.SqlException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL130406103359120' defined on 'ACCOUNT'.

如果不运行导入,我可以创建一个用户就好了。在我看来,导入不考虑表中指定的AUTO_INCREMENT函数。我不应该使用AUTO_INCREMENT4更新为ALTER TABLE ACCOUNT AUTO_INCREMENT = 4;,我应该吗?

1 个答案:

答案 0 :(得分:1)

执行导入后,执行:

ALTER TABLE ACCOUNT ALTER COLUMN ID RESTART WITH 4

请参阅此链接:http://db.apache.org/derby/docs/10.9/ref/rrefsqlj81859.html#rrefsqlj81859__rrefsqlj37860