Derby autogenereted keys
Thoralf Rickert <[email protected]>
| Newsgroups | gmane.comp.jakarta.turbine.torque.user |
|---|---|
| Message-ID | <A864307CE9C0D54191507125C95FC59E578B21CD@srv-exchange.cadooz-ag.intern> |
Hi,
I couldn't find any questions/answers nor a tutorial about my current problem, so I'm not sure, if this is a user bug or a real problem. But I hope, you have an answer for me.
I want to use Derby 10.4 and Torque 3.3 to implement an embedded database into a small GUI application. I'm new to Derby so that I'm not sure, where my problem really is.
I've defined a table:
<table name="report">
<column name="id" required="true" type="BIGINT" primaryKey="true" autoIncrement="true"/>
<column name="filename" required="true" type="VARCHAR" size="1024"/>
<unique>
<unique-column name="filename"/>
</unique>
</table>
The important point is the "autoIncrement". The generated SQL code does'nt contain any informations about this.
CREATE TABLE report
(
id BIGINT NOT NULL,
filename VARCHAR(1024) NOT NULL,
PRIMARY KEY(id),
UNIQUE (filename)
);
This means - no autogenerated keys. I don't want to use IDBroker if the database is able to generate the keys. Actually I found out, that Derby is able to generate autogenerated keys with "GENERATED ALWASY AS IDENTITY". But Torque seems not not use this feature. When I run this SQL statement manually...
CREATE TABLE report
(
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY,
filename VARCHAR(1024) NOT NULL,
PRIMARY KEY(id),
UNIQUE (filename)
);
The table is generated as I wanted. But then the next problem is, that I cannot INSERT any values via Torque because it tries to save/set an ID value. I'll get an SQLSyntaxException "Attempt to modify an identity column 'ID'" from Derby.
I could define a default value "DEFAULT" for the primary key as Derby wanted and use GENERATED BY DEFAULT but I cannot setup a default String value "default" for a long field (compile error).
Any ideas?
Thanks
Thoralf
smime.p7s
(application/x-pkcs7-signature, 1.9 KB) - not displayed