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 98163

Summary: Entity Classes from DB: incorrect method names for classes generated from join table
Product: javaee Reporter: michaelm001 <michaelm001>
Component: PersistenceAssignee: Dongmei Cao <dongmeic>
Status: RESOLVED FIXED    
Severity: blocker CC: abadea
Priority: P3    
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description michaelm001 2007-03-19 00:20:58 UTC
In netbeans 5.5, when selecting:

new file...
persistence...
Entity Class from database...
select databse connection...
select 'all' tables...
next...
finish...

Classes are generated from the following tables:

CREATE TABLE app_user
(
    app_user_id   INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 
1),

    name          VARCHAR(32)  NOT NULL,
    password      VARCHAR(32)  NOT NULL,
    creation_date TIMESTAMP DEFAULT CURRENT TIMESTAMP,
    expires       TIMESTAMP,
    person_id     INTEGER NOT NULL,

    CONSTRAINT    app_user_pk   PRIMARY KEY (app_user_id),
    CONSTRAINT    app_user_uk1  UNIQUE      (name, person_id),
    CONSTRAINT    app_user_fk1  FOREIGN KEY (person_id)   REFERENCES person (person_id)
);

CREATE TABLE app_role
(
    app_role_id   INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 
1),

    name          VARCHAR(32)  NOT NULL,
    description   VARCHAR(120) NOT NULL,

    CONSTRAINT    app_role PRIMARY KEY (app_role_id)
);

CREATE TABLE app_user_role
(
    app_user_id      INTEGER NOT NULL,
    app_role_id      INTEGER NOT NULL,

    CONSTRAINT       app_user_role_pk   PRIMARY KEY (app_user_id, app_role_id),
    CONSTRAINT       app_user_role_fk1  FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id) 
on delete cascade,
    CONSTRAINT       app_user_role_fk2  FOREIGN KEY (app_role_id) REFERENCES app_role (app_role_id) 
on delete cascade
);

app_user_role is the join table.

When the classes are generated, the AppUser.java contains incorrectly named methods:

    /**
     * Gets the appRoleIdCollection of this AppUser.
     * @return the appRoleIdCollection
     */
    public Collection<AppRole> getAppRoleIdCollection()
    {
        return this.appRoleIdCollection;
    }

    /**
     * Sets the appRoleIdCollection of this AppUser to the specified value.
     * @param appRoleIdCollection the new appRoleIdCollection
     */
    public void setAppRoleIdCollection(Collection<AppRole> appRoleIdCollection)
    {
        this.appRoleIdCollection = appRoleIdCollection;
    }

These should be:

getAppRoleCollection
setAppRoleCollection

Additionally, the AppRole.java has these:

    /**
     * Gets the appUserIdCollection of this AppRole.
     * @return the appUserIdCollection
     */
    public Collection<AppUser> getAppUserIdCollection()
    {
        return this.appUserIdCollection;
    }

    /**
     * Sets the appUserIdCollection of this AppRole to the specified value.
     * @param appUserIdCollection the new appUserIdCollection
     */
    public void setAppUserIdCollection(Collection<AppUser> appUserIdCollection)
    {
        this.appUserIdCollection = appUserIdCollection;
    }

these should be:

getAppUserCollection
setAppUserCollection

Notice that the collection types ARE correct, but the method names are not correct.

the 'get' and 'set' should match the type of the collection returned.

getAppUserIdCollection is not getAppUserCollection.
Comment 1 Dongmei Cao 2008-05-15 19:22:14 UTC
Checked in fix - http://hg.netbeans.org/main/rev/bb5370829871
Comment 2 Dongmei Cao 2008-05-19 22:19:02 UTC
*** Issue 77696 has been marked as a duplicate of this issue. ***