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 83323 - [55cat] Entities from Database wizard - unexpected error when generating entities
Summary: [55cat] Entities from Database wizard - unexpected error when generating enti...
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 5.x
Hardware: PC All
: P3 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-23 23:05 UTC by hsalameh
Modified: 2006-09-08 16:03 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
dbschema file (147.96 KB, text/xml)
2006-08-29 00:16 UTC, Rochelle Raccah
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hsalameh 2006-08-23 23:05:48 UTC
[ JDK VERSION : 1.5.0_06 ]

I get an "Unexpected Error" message when generating entities from database with the schema attached below. I am using derby as the database.

create table CUSTOMER (
                ID                                    INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
                FIRST_NAME                            VARCHAR(255),
                MIDDLE_NAME                           VARCHAR(255),
                LAST_NAME                             VARCHAR(255),
                PRIMARY_ADDRESS_LINE1                 VARCHAR(255),
                PRIMARY_ADDRESS_LINE2                 VARCHAR(255),
                PRIMARY_ADDRESS_CITY                  VARCHAR(255),
                PRIMARY_ADDRESS_STATE_ID              INTEGER,
                PRIMARY_ADDRESS_ZIP                   VARCHAR(255),
                SECONDARY_ADDRESS_LINE1               VARCHAR(255),
                SECONDARY_ADDRESS_LINE2               VARCHAR(255),
                SECONDARY_ADDRESS_CITY                VARCHAR(255),
                SECONDARY_ADDRESS_STATE_ID            INTEGER,
                SECONDARY_ADDRESS_ZIP                 VARCHAR(255)
                );

create table STATE(
                ID                                    INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
                NAME                                  VARCHAR(255) NOT NULL,
                CODE                                  VARCHAR(255) NOT NULL
                );

ALTER TABLE STATE ADD CONSTRAINT INDEX_STATE_NAME UNIQUE (NAME);
ALTER TABLE STATE ADD CONSTRAINT INDEX_STATE_CODE UNIQUE (CODE);
                

alter table CUSTOMER
                add constraint  FK_CUSTOMER_PRIMARY_ADDRESS_STATE_ID
                foreign key     (PRIMARY_ADDRESS_STATE_ID)
                references      STATE (ID);

alter table CUSTOMER
                add constraint  FK_CUSTOMER_SECONDARY_ADDRESS_STATE_ID
                foreign key     (SECONDARY_ADDRESS_STATE_ID)
                references      STATE (ID);
Comment 1 Rochelle Raccah 2006-08-24 00:44:56 UTC
I can reproduce.  The problem is that the list of inverse column names for
setting up the JoinColumn referencedColumnName annotation for the field
corresponding to SECONDARY_ADDRESS_STATE_ID in class Customer is null.  I'm not
sure why yet, but I'm looking into it.
Comment 2 Rochelle Raccah 2006-08-24 01:58:23 UTC
More info - the problem is that
1) there are 2 fks in CUSTOMER to STATE.ID (one on PRIMARY_ADDRESS_STATE_ID and
one on SECONDARY_ADDRESS_STATE_ID)
2) the uniqueing cleanup of DbSchemaEjbGenerator.makeBeansUnique updated in the
fix for issue 80084 (see
<http://www.netbeans.org/source/browse/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Attic/DbSchemaEjbGenerator.java?r1=1.1.2.1.2.10&r2=1.1.2.1.2.11>)
*removes* the second cmr field mapping from the map
Comment 3 Rochelle Raccah 2006-08-29 00:13:03 UTC
If I remove Andrei's fix for issue 80084, this bug is fixed and I can't seem to
reproduce issue 80084.  I tried to do so using the ddl Pavel had in issue 80084,
but I no longer have both a cmp and cmr field for the overlap.

I'll attach a dbschema with 4 tables - 2 based on the ones in this issue and 2
based on the ones in issue 80084.

Transferring to Andrei after discussion with Pavel.
Comment 4 Rochelle Raccah 2006-08-29 00:16:15 UTC
Created attachment 33339 [details]
dbschema file
Comment 5 Andrei Badea 2006-09-08 16:03:14 UTC
Yes, it seems my "fix" can be removed, because the CMR mapping already contains
the uniquified field names. Rochelle, thank you for spending time on this!

Checking in DbSchemaEjbGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Attic/DbSchemaEjbGenerator.java,v
 <-- DbSchemaEjbGenerator.java
new revision: 1.1.2.1.2.12; previous revision: 1.1.2.1.2.11
done