I\'m coming from MySQL world, please help.
Is it possible to create autoincrement key from NetBeans IDE in JavaDB?
Do you use some more advanced db clients,
I couldn't get the accepted answer to work using the Netbeans IDE "Create Table" GUI, and I'm on Netbeans 8.2. To get it to working, create the id column with the following options e.g.
and then use 'New Entity Classes from Database' option to generate the entity for the table (I created a simple table called PERSON with an ID column created exactly as above and a NAME column which is simple varchar(255) column). These generated entities leave it to the user to add the auto generated id mechanism.
GENERATION.AUTO seems to try and use sequences which Derby doesn't seem to like (error stating failed to generate sequence/sequence does not exist), GENERATION.SEQUENCE therefore doesn't work either, GENERATION.IDENTITY doesn't work (get error stating ID is null), so that leaves GENERATION.TABLE.
Set your persistence unit's 'Table Generation Strategy' button to Create. This will create tables that don't exist in the DB when your jar is run (loaded?) i.e. the table your PU needs to create in order to store ID increments. In your entity replace the generated annotations above your id field with the following...
I also created a controller for my entity class using 'JPA Controller Classes from Entity Classes' option. I then create a simple main class to test the id was auto generated i.e.
The result is that the PERSON_ID_TABLE is generated correctly and my PERSON table has two PERSON entries in it with correct, auto generated ids.
It's not possible right now, on Netbeans 7.0.1 . The GUI tool to create columns on a tables is very limited and does not exist a plugin that offer that feature.
If you look at this url: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/
this part of the schema may be what you are looking for.
ID INTEGER NOT NULL
PRIMARY KEY GENERATED ALWAYS AS IDENTITY
(START WITH 1, INCREMENT BY 1),
Found a way of setting auto increment in netbeans 8.0.1 here on StackoOverflow Screenshot below:
Voila!!
This may help you:
CREATE TABLE "custinf"
(
"CUST_ID" INT not null primary key
GENERATED ALWAYS AS IDENTITY
(START WITH 1, INCREMENT BY 1),
"FNAME" VARCHAR(50),
"LNAME" VARCHAR(50),
"ADDR" VARCHAR(100),
"SUBURB" VARCHAR(20),
"PCODE" INTEGER,
"PHONE" INTEGER,
"MOB" INTEGER,
"EMAIL" VARCHAR(100),
"COMM" VARCHAR(450)
);
That's how i got mine to work... to ages to get the frigging thing to actually understand me but that's the nature of code :D
BTW!- There is a way to do it in the ide interface goto the services window, expand your connection, expand your projects name, expand tables, right click indexes and select add index... the rest of the process speaks for itself really...