This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Environment: Netbeans 6.5.1 / 6.7 RC3 running on JDK 1.6.0.13/14 Database: Firebird using Jaybird 2.1.5 Observed behaviour: When using the "New Entity Classes from Database" feature, some tables will inexplicably be marked as "(no primary key)" and cannot be selected/added/processed. The tables are from an operational database, and all tables in this database have a primary key (a BIGINT/INT64 surrogate key). I can confirm that this issue is found on 6.5.1, and 6.7 RC3. I can test this against earlier versions if needed. Expected behaviour: 1. A table with a PRIMARY KEY should be recognized as such. 2. assuming there's a bug in the "primary key detection", provide a way for the user to "force create" the entity, with the understanding that the user might have to edit the entity by hand if necessary. 3. If this situation is caused by different behaviour from various JDBC driver implementations, provide a clear explanation to the user why Netbeans thinks that the table doesn't have a primary key. Just saying "Table cannot be added because it does not have a primary key" (while the table obviously does, according to db admin tools) is not helping much. So far i cannot see any discernable patterns from the rejected tables. Some are complex tables with 30+ fields and at least 7 FK links, but some simple lookup tables got rejected also. Here's an example DDL of a simple table that got rejected. create table EX_USER ( EX_USER_ID T_ID not null, EX_USER_CODE T_CODE not null, EX_USER_NAME T_STRING, EX_USER_BLAH T_STRING, EX_USER_HASH T_LONGSTRING, EX_DESCRIPTION T_STRING, EX_TIMESTAMP T_TIMESTAMP, constraint PK_EX_USER primary key (EX_USER_ID), constraint AK_EX_USER_CODE_EX_USER unique (EX_USER_CODE) );
Update 1 [2009-06-20] Today I started with a new test database containing just one table from the sample DDL i posted earlier, and the table was accepted, so it seems that the table by itself is not the problem, but some interactions with other tables are causing Netbeans to arrive at the "no primary key" conclusion. I managed to isolate the sample problem in the DDL below. The script will create three tables (CB_USER, CB_ROLE, and CB_USER_ROLE). If you just create the first two, Netbeans will process the tables just fine, but as soon as you add the third one (CB_USER_ROLE), the "New Entity Classes from Database" feature will mark table CB_USER as "no primary key". This is really baffling. I tried removing all the FK/UNIQUE constraints to no avail. Thanks. ////////////////////////////////////////////////////////////// create table CB_USER ( CB_USER_ID T_ID not null, CB_USER_CODE T_CODE not null, CB_USER_NAME T_STRING, DESCRIPTION T_STRING, constraint PK_CB_USER primary key (CB_USER_ID), constraint AK_CB_USER_CODE_CB_USER unique (CB_USER_CODE) ); ////////////////////////////////////////////////////////////// create table CB_ROLE ( CB_ROLE_ID T_ID not null, CB_ROLE_CODE T_CODE not null, CB_ROLE_NAME T_STRING, DESCRIPTION T_STRING, constraint PK_CB_ROLE primary key (CB_ROLE_ID), constraint AK_CB_ROLE_CODE_CB_ROLE unique (CB_ROLE_CODE) ); ////////////////////////////////////////////////////////////// create table CB_USER_ROLE ( CB_USER_ROLE_ID T_ID not null, CB_ROLE_ID T_ID not null, CB_USER_ID T_ID not null, DESCRIPTION T_STRING, constraint PK_CB_USER_ROLE primary key (CB_USER_ROLE_ID), constraint AK_UNIQUE_USER_ROLE_CB_USER_ unique (CB_ROLE_ID, CB_USER_ID) ); alter table CB_USER_ROLE add constraint FK_CB_USER_ROLE_x_CB_ROLE foreign key (CB_ROLE_ID) references CB_ROLE (CB_ROLE_ID); alter table CB_USER_ROLE add constraint FK_CB_USER_ROLE_x_CB_USER foreign key (CB_USER_ID) references CB_USER (CB_USER_ID); //////////////////////////////////////////////////////////////
*** Issue 169375 has been marked as a duplicate of this issue. ***
Details from the issue 169375: ------- Additional comments from ebcorde Tue Jul 28 18:33:27 +0000 2009 ------- If a database tables has no primary keys, the Netbeans Database application will not work with that table. It's Postgresql ver 8.2
I can conform this bug with Netbeans 6.8, MySQL 5 InnoDB. The good news is: I found a workaround. I also found that Netbeans seems to have a problem handling tables with fk relationships. After struggling for a few hours I decided to switch back to Eclipse. In Eclipse I ran into another issue. It was able to generate entities, but it totally ignored all the relations (One-to-Many, Many-to-Many etc). Manuel Chacon's experienced the same behaviour and found a solution (workaround..) he wrote: "Something that gave me a hard time is that for some funky reason the table names must be all in lower case. If tables names are in mixed case the relationships will not be discovered during the reverse engineering process. During my experimentation I discovered that the Middlegen docs give a warning about this, so I am guessing that the Eclipse DALI plugin uses Middlegen under the covers. The MySQL engine should also be INNODB." Luckily I am the owner of the database I can changed the mixedCaseTablenames to all_lower_case. After doing this, Netbeans generated my complete database without any complains. Jiri Rechtacek: As you are the assigned developer I hope this will give you some helpful information about the 'bug'. I don't this it's netbeans. I suspect the MySQL jdbc driver, because that's the only thing i know is shared betweens netbeans and eclipse dali.. :) I am using version: 5.1.6. All other users: rename table names in MySQL to all_lower_case. use the '_' because it will be concerted to CamelCase entities.
synpro, thank you for evaluation of the problem. Closing this as WONTFIX because it's the problem mysql driver.
The original issue has nothing to do with mysql or mysql driver. User "synpro" reported a somewhat different and maybe unrelated(?) issue. As of Netbeans 6.8, the issue is still unresolved and this makes the JPA generation feature unusable for me. Please let me know if you need more information about the problem.
sugihartolim, I'm sorry Firebird is not of supported databases and we have no plans to fix this in the near future. Patches are welcome.
I'm having the same problem on NB 7.0 MySQL 5.1.44 On a table name all lowercase (`company`). So it seams the workaround is not working. Best. Impe
(In reply to comment #8) > I'm having the same problem on > NB 7.0 > MySQL 5.1.44 > On a table name all lowercase (`company`). > > So it seams the workaround is not working. > > Best. > Impe Give me please more details: DDL command for creating `company` table (or more table if needed), name and version of JDBC driver and other details if relevant in this matter. Thanks
I had this same issue on the following configuration: Product Version: NetBeans IDE 7.0 (Build 201104080000) Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11 System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb) MySQL: 5.5.11 The only tables that NB couldn't find a PK were those that had gone through name changes alternating capitalized and non-capitalized names. I exported my database, created a new MySQL instance. Changed the value of the lower_case_table_names MySQL Parameter from 2 to 1. (0-Case Sensitive comparison of table names; 1-Stores lowercase & case insensitive comparisons; 2-Stores as given, but compares in lowercase.) Then imported the original data into the new instance. Using the new instance, NB was able to see each table's primary key. Seems that this issue may be associated with a change of table names combined with the setting of the lower_case_table_names parameter in MySQL.
I've pinned down the problem. Im using NetBeans IDE 7.1 (Build 201112071828) The problem will happen if you have foreign keys where upper case and lower case table names don't match the referenced table's definition. For instance: create table OkTable ( id int not null auto_increment , primary key (id) ); create table MisunderstoodTable( id int not null auto_increment oktable int not null , primary key (id) , foreign key ok (oktable) references oktable (id) ); The 'MisunderstoodTable' has a foreign key where the target table name doesn't match the lower/uppercase name of the referenced table. To avoid this problem, just make sure you type your foreign key definitions while matching upper/lower casing for the targeted table.
Those of us who can't modify the database are out of luck with Netbeans 7.1.1. You can glo use Oracle JDeveloper which handles this where Netbeans does not. Oh well. Maybe it will be fixed in the next rev.
is there any new information about this bug? I do have the same problem and can't modify the database like suggested. Im using ver. 7.1.2 201204101705 and tried also version 7.2 Beta (same problem here).
http://hg.netbeans.org/core-main/rev/e2a8a9927b2a Fixed, please verify. Thank you for diagnosing.
Integrated into 'main-golden', will be available in build *201206010001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/e2a8a9927b2a User: Jaroslav Havlin <jhavlin@netbeans.org> Log: #167389: "New Entity Classes from Database" cannot process some tables, saying "no primary key"
first of all ty for the responses. I just installed all 3 new dev builds (http://bits.netbeans.org/dev/nightly/) - 201206010001 - 201206020001 - 201206040001 but still have the same problem ("New Entity Classes from Database" cannot process some tables, saying "no primary key") My tables are on an Oracle DB ver. 10.2.0.3 but i don't think this should make a difference. 7 of 20 tables are marked grey in the pop-up menu saying "no primary key" but there is one on each table.
> My tables are on an Oracle DB ver. 10.2.0.3 but i don't think this should make > a difference. There can be some difference. The fix solves lowercase problems on MySQL. Do you have any foreign keys in you database that could cause that problem (see comment 11). Or any other observations or ideas? Are the tables for which entity classes cannot be created somehow special? Thank you.
the tables that are marked grey do have foreign keys like in "comment 11" described but all written in UPPER_CASE (also the referenced tables) but there are also tables without foreign keys marked with "no primary key". And no there is nothing special on the tables. I have no idea what could cause the problem. Maybe im just doing something wrong. Example (this is one table that i can't import) with foreign key. I'm using the oracle thin driver (also tried ORACLE OCI): CREATE TABLE "PRZMGNT"."JOBS" ( "ID" NUMBER(*,0) NOT NULL ENABLE, "CODE" VARCHAR2(30 BYTE) NOT NULL ENABLE, "NAME" VARCHAR2(200 BYTE) NOT NULL ENABLE, "PMANK_DWH_ID" NUMBER(*,0), "DWH_LAUF_GROUP" VARCHAR2(30 BYTE), "OWNER" VARCHAR2(200 BYTE) NOT NULL ENABLE, "OBJECT" VARCHAR2(200 BYTE) NOT NULL ENABLE, "MODULE" VARCHAR2(200 BYTE) NOT NULL ENABLE, "ALLOWED_MESSAGE_TYPES" NUMBER NOT NULL ENABLE, "ALLOWED_BUSINESS_TYPES" NUMBER NOT NULL ENABLE, "PARTITION_LABEL" VARCHAR2(5 BYTE) NOT NULL ENABLE, "COMMENT" VARCHAR2(2000 BYTE), "PROVIDER_EXPRESSION" VARCHAR2(2000 BYTE), "FLAG_USE_PROVIDER" VARCHAR2(1 BYTE) DEFAULT 'Y' NOT NULL ENABLE, "FLAG_RUN_ALLOWED" VARCHAR2(1 BYTE) DEFAULT 'Y' NOT NULL ENABLE, "FLAG_RESTART_ALLOWED" VARCHAR2(1 BYTE) DEFAULT 'N' NOT NULL ENABLE, CONSTRAINT "PK_ID" PRIMARY KEY ("ID") USING INDEX TABLESPACE "USERS" ENABLE, CONSTRAINT "UK_CODE" UNIQUE ("CODE") USING TABLESPACE "USERS" ENABLE, CONSTRAINT "UK_PMANK_NAME" UNIQUE ("PMANK_DWH_ID", "NAME")TABLESPACE "USERS" ENABLE, CONSTRAINT "CHK_CODE" CHECK ( INSTR( CODE, ':' ) = 0 ) ENABLE, CONSTRAINT "CHK_CODE_STR_CFG" CHECK ( INSTR( CODE, 'PS_OR' ) = 0 ) ENABLE, CONSTRAINT "CHK_FLAG_USE_PROVIDER" CHECK ( FLAG_USE_PROVIDER IN ('Y', 'N' )) ENABLE, CONSTRAINT "CHK_FLAG_RUN_ALLOWED" CHECK ( FLAG_RUN_ALLOWED IN ('Y', 'N' ) ) ENABLE, CONSTRAINT "CHK_FLAG_RESTART_ALLOWED" CHECK (FLAG_RESTART_ALLOWED IN ( 'Y', 'N' ) ) ENABLE, CONSTRAINT "CHK_PARTITION_LABEL" CHECK ( PARTITION_LABEL IN ( 'M', 'Q', 'Y', '2Y', '10Y' ) ) ENABLE, CONSTRAINT "CHK_PMANK" CHECK ( ( OWNER = 'USERNAME'AND PMANK_DWH_ID IS NOT NULL ) OR(OWNER != 'USERNAME')) ENABLE, CONSTRAINT "FK_PMANK" FOREIGN KEY ("PMANK_DWH_ID") REFERENCES "PMANK_MANDANT" ("PMANK_DWH_ID") ENABLE) TABLESPACE "USERS" ;
> Example (this is one table that i can't import) with foreign key. Strange, I created the table (and a dummy table for the foreign key), but the import works fine. Could you please also attach an example table with no foreign keys? The code that you attached was the original statement that had created the table or a generated script? Can it make some difference?
(In reply to comment #19) > > Example (this is one table that i can't import) with foreign key. > Strange, I created the table (and a dummy table for the foreign key), but the > import works fine. > Could you please also attach an example table with no foreign keys? > The code that you attached was the original statement that had created the > table or a generated script? Can it make some difference? the code was the oracle table created script. The original script is another one. But it shouldn't make a difference. Really strange, i did the same, dropped all tables and created just 2 of 20, and it worked. But if i first create all 20 tables with their references it won't work. one example without FK: CREATE TABLE "PMANK_MANDANT" ( "PMANK_ID" NUMBER(*,0) NOT NULL ENABLE, "PMANK_CODE" VARCHAR2(30 BYTE) NOT NULL ENABLE, "PMANK_NAME" VARCHAR2(100 BYTE) NOT NULL ENABLE, "PMANK_VERARBEITUNGSMERKMAL" VARCHAR2(100 BYTE), "PMANK_INS_TIMESTAMP" TIMESTAMP (6) NOT NULL ENABLE, "PMANK_INS_USER" VARCHAR2(100 BYTE) NOT NULL ENABLE, "PMANK_UPD_TIMESTAMP" TIMESTAMP (6), "PMANK_UPD_USER" VARCHAR2(100 BYTE), CONSTRAINT "PMANK_PK" PRIMARY KEY ("PMANK_ID") USING INDEX TABLESPACE "USERS" ENABLE, CONSTRAINT "UK_PMANK_CODE" UNIQUE ("PMANK_CODE") USING INDEX TABLESPACE "USERS" ENABLE, CONSTRAINT "UK_PMANK_NAME" UNIQUE ("PMANK_NAME") USING INDEX TABLESPACE "USERS" ENABLE ) TABLESPACE "USERS" ; CREATE UNIQUE INDEX "IDX_PMANK_CODE" ON "PMANK_MANDANT" ( "PMANK_CODE" ) TABLESPACE "USERS" ; CREATE UNIQUE INDEX "IDX_PMANK_NAME" ON "PMANK_MANDANT" ( "PMANK_NAME" ) TABLESPACE "USERS" ; CREATE INDEX "IDX_PMANK_PK" ON "PMANK_MANDANT" ( "PMANK_ID" ) TABLESPACE "USERS" ; CREATE OR REPLACE TRIGGER "TRG_PMANK_BIU" BEFORE INSERT OR UPDATE ON PMANK_MANDANT FOR EACH ROW BEGIN IF INSERTING THEN IF :NEW.PMANK_ID IS NULL THEN SELECT SEQ_PMANK.NEXTVAL INTO :NEW.PMANK_ID FROM DUAL ; END IF; :NEW.PMANK_INS_TIMESTAMP := SYSTIMESTAMP; :NEW.PMANK_INS_USER := USER || ':' || sys_context('USERENV','OS_USER') ; ELSIF UPDATING THEN :NEW.PMANK_INS_TIMESTAMP := :OLD.PMANK_INS_TIMESTAMP ; :NEW.PMANK_INS_USER := :OLD.PMANK_INS_USER ; :NEW.PMANK_UPD_TIMESTAMP := SYSTIMESTAMP; :NEW.PMANK_UPD_USER := USER || ':' || sys_context('USERENV', 'OS_USER') ; END IF; END; / ALTER TRIGGER "TRG_PMANK_BIU" ENABLE;
OK, if i create a table (like in my original script) and then ALTER TABLE JOBS ADD CONSTRAINT PK_PSJO PRIMARY KEY ( ID ) USING INDEX IDX_ID; the table will be marked grey in the entity classes window. only if i do it like this it will work CREATE TABLE "PSJO_JOBS" .... CONSTRAINT "PK_PSJO" PRIMARY KEY ("PSJO_ID") , ...
I'm sorry, still cannot reproduce (tried steps in comment 20 and comment 21). It would be great if you could attach a simple script that creates tables in an empty database, and that demonstrates the bug. Thank you for your help.
(In reply to comment #22) > I'm sorry, still cannot reproduce (tried steps in comment 20 and comment 21). > It would be great if you could attach a simple script that creates tables in an > empty database, and that demonstrates the bug. Thank you for your help. OK, last one. What i described in "comment 21" wasn't the problem. If you can please create this 2 tables "TEST_UI" and "TEST_UI2". "TEST_UI" does have 2 UNIQUE INDEXES where "TEST_UI2" only have 1. This should be the problem. Thanks for your help. CREATE TABLE TEST_UI ( ID INTEGER NOT NULL , CODE VARCHAR2(30) NOT NULL , NAME VARCHAR2(200) NOT NULL ); CREATE INDEX IDX_ID ON TEST_UI (ID); CREATE UNIQUE INDEX IDX_CODE ON TEST_UI (CODE); CREATE UNIQUE INDEX IDX_CODE_NAME ON TEST_UI (CODE, NAME); ALTER TABLE TEST_UI ADD CONSTRAINT PK_TEST_UI PRIMARY KEY (ID); CREATE TABLE TEST_UI2 ( ID INTEGER NOT NULL , CODE VARCHAR2(30) NOT NULL , NAME VARCHAR2(200) NOT NULL ); CREATE INDEX IDX_ID_TEST_UI ON TEST_UI2 (ID); CREATE UNIQUE INDEX IDX_CODE_TEST_UI ON TEST_UI2 (CODE); ALTER TABLE TEST_UI2 ADD CONSTRAINT PK_TEST_UI2 PRIMARY KEY (ID);
http://hg.netbeans.org/core-main/rev/e116876c7eff Reproduced, thank you very much. The problem was that the primary key had a corresponding index that was not unique, but there were some other unique indexes. This is a valid situation and is handled correctly now. Fixed, hopefully. Please verify.
Integrated into 'main-golden', will be available in build *201206070001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/e116876c7eff User: Jaroslav Havlin <jhavlin@netbeans.org> Log: #167389: "New Entity Classes from Database" cannot process some tables, saying "no primary key"
I saw the current status of this bug before posting and can say this problem happened to me in 7.3.1* (with latest updates)and Oracle 10g. The solution for me is to go to Databases in the Services tab and check the connection (connected to and tried a query). After that I can use my 100+ tables in the "New Entity Classes from Database" wizard, of which, at first, most of them where unavailable (in gray, unselectable) because of "no primary key" thing. If I don't test the connection as described above I get "<put your connection here> seems to be broken. Cause: java.sql.SQLException: OALL8 is in an inconsistent state". Then, I click Ok and I can't use most of the tables because of "no primary key". Not the best solution, I think, because primary keys are "there", yet invisible. *I can't update at this moment to 7.4+ to check if the error doesn't show up.
Hi, first sorry for my english. I have tried all you've said in the comments above but i still have the same problem: I try to create a RestFul webservice From database but i don't know what happen. My script sql is: https://www.dropbox.com/s/g4bt4n2frqfoufq/bbdd_cuadro_mando%20%281%29.sql The tables which have the problem are 'mediciones' and 'redes'. Can anyone help me? Anyone knows anything new about this bug? I'm using Ubuntu 14.00, MySQL 5.5.37, Netbeans 8.0 and JDBC driver for mySQL. Thanks.