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 188239 - JSF from entity wizard generates code with errors for entities with composite primary keys
Summary: JSF from entity wizard generates code with errors for entities with composite...
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSF (show other bugs)
Version: 6.x
Hardware: PC Mac OS X
: P2 normal (vote)
Assignee: Alexey Butenko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-30 13:32 UTC by Kenneth Ganfield
Modified: 2010-07-12 07:44 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Ganfield 2010-06-30 13:32:45 UTC
Using NetBeans 6.9
JSF 1.2
GlassFish 2 or 3

When using the JSF from entity wizard, the wizard generates code with errors in the getAsString method of converter classes for entities when the table has composite primary keys. This worked in 6.8

When using JSF 2.0, the generated code is fine (although totally different)

The steps are outlined in this tutorial:
http://netbeans.org/kb/docs/web/jsf-jpa-crud-wizard.html

The tutorial uses a mysql database named consult and the script to create the db can be found here:
http://kenai.com/projects/consultingagencysol/downloads/download/base/mysql-consult.zip

Basically, when following the instructions, the wizard generates code with errors in the two converter classes for the entities CLIENT and PROJECT.

Here you can see the difference between the code generated in 6.9 and 6.8
Code generated by NetBeans 6.9.

 public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof Client) {
            Client o = (Client) object;
            ClientPK id = o.getClientPK();
            if (id == null) {
                return "";
            }
            String delim = "#";
            String escape = "~";


            String setClientName;
            id.getClientName();
            setClientName() = setClientName() == null ? "" : setClientName().replace(escape, escape + escape);
            setClientName() = setClientName().replace(delim, escape + delim);
            Object setClientDepartmentNumber;
            Obj = id.getClientDepartmentNumber();
            String setClientDepartmentNumber;
            setClientDepartmentNumber();
            (ERROR);
            (ERROR);
            setClientDepartmentNumber() = setClientDepartmentNumber().replace(escape, escape + escape);
            setClientDepartmentNumber() = setClientDepartmentNumber().replace(delim, escape + delim);
            return setClientName() + delim + setClientDepartmentNumber();


            // TODO: no setter methods were found in your primary key class
            //    jpa.entities.ClientPK
            // and therefore getAsString() method could not be pre-generated.
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: jpa.entities.Client");
        }
    }

Code generated by NetBeans 6.9

 public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof Client) {
            Client o = (Client) object;
            ClientPK id = o.getClientPK();
            if (id == null) {
                return "";
            }
            String delim = "#";
            String escape = "~";


            String clientName = id.getClientName();
            clientName = clientName == null ? "" : clientName.replace(escape, escape + escape);
            clientName = clientName.replace(delim, escape + delim);
            Object clientDepartmentNumberObj = id.getClientDepartmentNumber();
            String clientDepartmentNumber = clientDepartmentNumberObj == null ? "" : String.valueOf(clientDepartmentNumberObj);
            clientDepartmentNumber = clientDepartmentNumber.replace(escape, escape + escape);
            clientDepartmentNumber = clientDepartmentNumber.replace(delim, escape + delim);
            return clientName + delim + clientDepartmentNumber;


            // TODO: no setter methods were found in your primary key class
            //    jpa.entities.ClientPK
            // and therefore getAsString() method could not be pre-generated.
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: jpa.entities.Client");
        }
    }
Comment 1 Alexey Butenko 2010-07-07 12:39:42 UTC
http://hg.netbeans.org/web-main/rev/9d7c21c8a29c
Comment 2 Petr Jiricka 2010-07-07 13:41:37 UTC
Cc'ing Martin - Martin, we are thinking this may be a 6.9.1 candidate, what do you think?
Comment 3 Martin Schovanek 2010-07-07 15:00:06 UTC
I think we should fix it for 6.9.1 . Going to verify it in trunk.
Comment 4 Quality Engineering 2010-07-08 03:26:08 UTC
Integrated into 'main-golden', will be available in build *201007080001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/9d7c21c8a29c
User: Alexey Butenko <alexeybutenko@netbeans.org>
Log: #188239: JSF from entity wizard generates code with errors for entities with composite primary keys
Comment 5 Martin Schovanek 2010-07-08 09:48:47 UTC
Cannot verify now due P1 trunk issue #188443
Comment 6 Martin Schovanek 2010-07-09 13:46:49 UTC
Verified at a custom build, please transplant into 6.9.1.
Comment 7 Martin Ryzl 2010-07-09 13:50:14 UTC
simple fix with bigger impact - I approve merge into 6.9.1
Comment 8 Alexey Butenko 2010-07-12 07:44:12 UTC
Transplanted into 6.9.1
http://hg.netbeans.org/release691/rev/80979b69597d