I have spring boot App with Derby Database. In application property file below is configuration.
spring.datasource.url=jdbc:derby://localhost:1600/derbydataLogger
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialize=false
CREATE TABLE "DCS"."DEVICES" (
"ID" bigint generated by default as identity,
"DEVICE_NAME" varchar(45) NOT NULL,
"IP_ADDRESS" varchar(60) NOT NULL,
"PORT" int NOT NULL,
"IS_CONNECTED" boolean DEFAULT false,
"UPDATED_DATE" TIMESTAMP DEFAULT NULL,
CONSTRAINT PK_devices_ID PRIMARY KEY ("ID")
);
I have noticed that when there is a table with an auto generated primary key, the auto incrementation by INSERT fails. Instead of increment the value by 1, sometimes Derby increments the primary key with 100 or 1000 or other random value.
I can't reproduce it, because it is random.
For example, I have a table named 'DEVICE', and i have inserted 4 rows, and I get the following the auto generated keys:
1. INSERT: auto generated primary key: 806
2. INSERT: auto generated primary key: 807
3. INSERT: auto generated primary key: *904*
4. INSERT: auto generated primary key: *1004*
5. INSERT: auto generated primary key: 1005
It should be incremented by 1. The expected sequence should be:
1. INSERT: auto generated primary key: 806
2. INSERT: auto generated primary key: 807
3. INSERT: auto generated primary key: 808
4. INSERT: auto generated primary key: 809
5. INSERT: auto generated primary key: 810
Has anybody met with this strange error? Do you have any suggestions, how to start to debug it? I can't reproduce it.