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 194461 - "RESTful Web Service From Entity Classes" can produce uncompilable code
Summary: "RESTful Web Service From Entity Classes" can produce uncompilable code
Status: RESOLVED WONTFIX
Alias: None
Product: webservices
Classification: Unclassified
Component: REST (show other bugs)
Version: 7.0
Hardware: PC Other
: P3 normal (vote)
Assignee: Denis Anisimov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-19 06:46 UTC by crued
Modified: 2011-01-19 10:44 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Web App Project with RESTful Web Services generated from entity classes resulting in uncompilable services (32.18 KB, application/zip)
2011-01-19 07:03 UTC, crued
Details

Note You need to log in before you can comment on or make changes to this bug.
Description crued 2011-01-19 06:46:54 UTC
Uncompilable source code can be generated by the"RESTful Web Services from Entity Classes..." wizard if it is run on two related entity classes when these classes have no getter and setter methods for the fields that relate them. The uncompilable classes are converter and service classes.



--------------------------------------------------------
Entity1.java: 
--------------------------------------------------------
...
@Entity
public class Entity1 implements Serializable {

    @OneToMany(mappedBy = "entity1")
    private List<Entity2> entity2s;

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}





--------------------------------------------------------
Entity2.java: 
--------------------------------------------------------
...
@Entity
public class Entity2 implements Serializable {

    @ManyToOne
    private List<Entity2> entity1;

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}




The "RESTful Web Services from Entity Classes..." seems to generate the converter classes with the assumption that these getter methods exist.

For example, it will generate the following method in Entity2Converter.java:

    @XmlElement
    public Entity1Converter getEntity1() {
        if (expandLevel > 0) {
            if (entity.getEntity1() != null) {
                return new Entity1Converter(entity.getEntity1(), uri.resolve("entity1/"), expandLevel - 1, false);
            }
        }
        return null;
    }

Note that the getEntity1() method does not exist and the code is uncompilable.




I suppose what I might expect here is for the wizard to create the required getter and setter methods in these entity classes (with confirmation).

It may also be sufficient to provide a message in the wizard indicating that the code generated will not compile when this occurs.
Comment 1 crued 2011-01-19 07:03:15 UTC
Created attachment 105135 [details]
Web App Project with RESTful Web Services generated from entity classes resulting in uncompilable services
Comment 2 Denis Anisimov 2011-01-19 09:31:46 UTC
Right the issue exists.
The scenario is uncommon because of bean attribute without accessor methods.

I would object from entity beans modifications. The entity beans are the 
original data and it is not good to modify the data.

I would suggest to change algorithm of source code generation.
Comment 3 Denis Anisimov 2011-01-19 10:44:24 UTC
This issue will not be fixed.
The reasons are:
1) For the nearest release this is not a big issue : absence of accessors for
entity attribute break the java beans contract. So the scenario is rare and 
not valid from very beginning.
2) There is an issue #189723 which is already fixed but I can't include 
the source code into the trunk for 7.0 release. There are a lot of code
changes and it is too risky. There will be no any converters but RESTful WS will 
handle corresponding entity only ( without its references ) after commit for 
mentioned issue . Any persistence aspects will be handled by persistence functionality ( JPA controller ).
So the original issue will just disappear .

The source code for RESTful WS will looks mostly the same as generated code
for WS with JEE6 profile. You can use this profile for your application 
because you use GF which supports JEE6 profile.