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.
The "convertor" classes for RESTful web services are not properly generated and the XML results are including same elements multiple times. See example of the output bellow. The part of the code that seems to cause problems is this: ----->8--- Genereated code @XmlRootElement(name = "prdBugs") public class PrdBugsConverter { private Collection<PrdBug> entities; private Collection<PrdBugConverter> items; private URI uri; private int expandLevel; ..... /** * Creates a new instance of PrdBugsConverter. * * @param entities associated entities * @param uri associated uri * @param expandLevel indicates the number of levels the entity graph should be expanded */ public PrdBugsConverter(Collection<PrdBug> entities, URI uri, int expandLevel) { this.entities = entities; this.uri = uri; this.expandLevel = expandLevel; getPrdBug(); } /** * Returns a collection of PrdBugConverter. * * @return a collection of PrdBugConverter */ @XmlElement public Collection<PrdBugConverter> getPrdBug() { if (items == null) { items = new ArrayList<PrdBugConverter>(); } if (entities != null) { for (PrdBug entity : entities) { items.add(new PrdBugConverter(entity, uri, expandLevel, true)); } } return items; } ---->8-- end of generated code The problem I see is that the function getPrdBug is called twice (once from the constructor and once from the framework) and each subsequent call of getPrdBug copies all the items from the entities collection into the items collection again. After removing the call of getPrdBug from the constructor the issue seems to be fixed, however something else may get broken - not tested. ------>8--- Example of the output <prdBugs uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/"> − <prdBug uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/"> <crId>123456</crId> <id>1</id> <idChangelog uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/idChangelog/"/> − <prdContainerCollection uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/"> <prdContainer uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/1/"/> <prdContainer uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/1/"/> </prdContainerCollection> <tstamp>2008-12-04T15:57:36+01:00</tstamp> </prdBug> − <prdBug uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/"> <crId>123456</crId> <id>1</id> <idChangelog uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/idChangelog/"/> − <prdContainerCollection uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/"> <prdContainer uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/1/"/> <prdContainer uri="http://localhost:8080/prd_ws_t007/resources/prdContainers/1/prdBugCollection/1/prdContainerCollection/1/"/> </prdContainerCollection> <tstamp>2008-12-04T15:57:36+01:00</tstamp> </prdBug> </prdBugs>
btw. the getPrdBug() call in the constructor was added in the plugin sometimes between v 0.8 and v 1.0.1, before it seemed to work properly ;-)
Peter, Ayub, can I ask you to evaluate this issue ASAP, please? Thanks.
btw: I'd like to add the fix for this to patch2 candidates list....
This is a bug in the generated code. The correct code should be /** * Returns a collection of PrdBugConverter. * * @return a collection of PrdBugConverter */ @XmlElement public Collection<PrdBugConverter> getPrdBug() { if (items == null) { items = new ArrayList<PrdBugConverter>(); } if (entities != null) { items.clear(); for (PrdBug entity : entities) { items.add(new PrdBugConverter(entity, uri, expandLevel, true)); } } return items; }
The line added "getXYZ()" to the constructor for dealing with lazy instantiation issue when Hibernate is used as the Persistence layer. So it will stay there.
Fixed.
.
v.
Can I ask you to add a link to changeset with the fix to this issue, please? Thanks.
Integrated into 'main-golden', will be available in build *200901140201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/c92d35a5eab3 User: Ayub Khan <ayubskhan@netbeans.org> Log: Fix issue#155640 - Entities are generated multiple times in RESTful web services
fix backported into release65_fixes branch http://hg.netbeans.org/release65_fixes/rev/9148e08f62c5