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.

Bug 258697 - "New Entity Classes from Database" entity classified as join table but is not.
Summary: "New Entity Classes from Database" entity classified as join table but is not.
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 8.1
Hardware: Macintosh Mac OS X
: P3 normal with 1 vote (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-06 22:42 UTC by ggonzalo
Modified: 2016-04-08 15:13 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Scripts and screenshot (17.98 KB, application/zip)
2016-04-06 22:42 UTC, ggonzalo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ggonzalo 2016-04-06 22:42:20 UTC
Created attachment 159140 [details]
Scripts and screenshot

Hello,

I have detected a problem when using the functionality "File->New" select category "Persistence" and file type "Entity Classes from Database". The creation is classifying incorrectly a 3rd entity as join table and is not created.
I saw bug 77152 to be similar, but it was not reproducible.

I have detected the problem to be the same in Oracle and Mysql databases.
I'm using NetBeans 8.1 but I have tried with older versions and is the same behaviour.
I work on a Mac, OS X El Capitan 

I have created the following example (Mysql commands):

CREATE TABLE TMP1 
(
  ID VARCHAR(3) NOT NULL 
, TMP1 TINYINT NOT NULL 
, NAME VARCHAR(15) NOT NULL 
, PRIMARY KEY (ID, TMP1) 
);

CREATE TABLE TMP2
(
  ID VARCHAR(3) NOT NULL 
, TMP2 TINYINT NOT NULL 
, NAME VARCHAR(15) NOT NULL 
,  PRIMARY KEY (ID, TMP2)
);

CREATE TABLE TMP3
(
  ID VARCHAR(3) NOT NULL 
, TMP1 TINYINT NOT NULL 
, TMP2 TINYINT NOT NULL 
, D1 DATE 
, PRIMARY KEY (ID, TMP1, TMP2)  
, CONSTRAINT FOREIGN KEY (ID, TMP1) REFERENCES TMP1 (ID, TMP1) 
, CONSTRAINT FOREIGN KEY (ID, TMP2) REFERENCES TMP2 (ID, TMP2) 
);

The table TMP3 is referencing TMP1 and TMP2 and adding an additional column.
When you try to use "Entity Classes from Database" you only get TMP1 and TMP2 and TMP3 is marked as join table.

I have figure out that this problem happens only when you have a primary key with two or more columns (@EmbeddedId) in the referencing tables.

Also I find out that if I add and extra column to TMP3, the TMP3 entity is created as expected.

CREATE TABLE TMP3
(
  ID VARCHAR(3) NOT NULL 
, TMP1 TINYINT NOT NULL 
, TMP2 TINYINT NOT NULL 
, D1 DATE 
, D2 DATE
, PRIMARY KEY (ID, TMP1, TMP2)  
, CONSTRAINT FOREIGN KEY (ID, TMP1) REFERENCES TMP1 (ID, TMP1) 
, CONSTRAINT FOREIGN KEY (ID, TMP2) REFERENCES TMP2 (ID, TMP2) 
);

I have attached the script for creating the tables and a screenshot.

Thank you
Comment 1 ggonzalo 2016-04-08 15:13:44 UTC
I also found that if the composed key has more columns, you need more extra columns in order to get the Entity created.

In the example I posted, my two primary keys are of two columns, so I think the source code for determining if it is a join table is adding 2 + 2 and if the total columns in the table is 4, it is a join table, but it is incorrect because one column is the same for both keys.

I you have a primary key of 3 columns, an other of 2 columns, the code is expecting at least 6 columns in the table in order to create the Entity but the table could have 4 columns only and not be a join table.