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.
Summary: | Generate RESTful webservice on self reference one to many produces non-compiling code | ||
---|---|---|---|
Product: | webservices | Reporter: | billrobertson42 <billrobertson42> |
Component: | REST | Assignee: | Ayub Khan <ayubskhan> |
Status: | RESOLVED DUPLICATE | ||
Severity: | blocker | ||
Priority: | P1 | ||
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | Project with the bug (see table.sql in com.example package) |
Description
billrobertson42
2009-02-09 03:14:48 UTC
Created attachment 76725 [details]
Project with the bug (see table.sql in com.example package)
I'm sure this will take time to fix etc... In the mean time, is it possible to add to the bug report what the broken methods should look like? This is a bug in our model builder for generating RESTful webservices. We fill fix this issue. In the meanwhile here is the correct code snippet. CategoriesResource.java ... /** * Persist the given entity. * * @param entity the entity to persist */ protected void createEntity(Category entity) { EntityManager em = PersistenceService.getInstance().getEntityManager(); em.persist(entity); for (Category value : entity.getCategoryCollection()) { Category oldEntity = value.getParentId(); value.setParentId(entity); if (oldEntity != null) { oldEntity.getCategoryCollection().remove(entity); } } Category parentId = entity.getParentId(); if (parentId != null) { parentId.getCategoryCollection().add(entity); } } CategoryResource.java ... /** * Updates entity using data from newEntity. * * @param entity the entity to update * @param newEntity the entity containing the new data * @return the updated entity */ protected Category updateEntity(Category entity, Category newEntity) { EntityManager em = PersistenceService.getInstance().getEntityManager(); Collection<Category> categoryCollection = entity.getCategoryCollection(); Collection<Category> categoryCollectionNew = newEntity.getCategoryCollection(); Category parentId = entity.getParentId(); Category parentIdNew = newEntity.getParentId(); entity = em.merge(newEntity); for (Category value : categoryCollection) { if (!categoryCollectionNew.contains(value)) { throw new WebApplicationException(new Throwable("Cannot remove items from categoryCollection")); } } for (Category value : categoryCollectionNew) { if (!categoryCollection.contains(value)) { Category oldEntity = value.getParentId(); value.setParentId(entity); if (oldEntity != null && !oldEntity.equals(entity)) { oldEntity.getCategoryCollection().remove(value); } } } if (parentId != null && !parentId.equals(parentIdNew)) { parentId.getCategoryCollection().remove(entity); } if (parentIdNew != null && !parentIdNew.equals(parentId)) { parentIdNew.getCategoryCollection().add(entity); } return entity; } This issue is duplicate of issue#152170, and is already fixed into 7.0 main branch. To test this you have to download dev build of NB7.0 from http://bits.netbeans.org/download/trunk/nightly/latest/ *** This issue has been marked as a duplicate of 152170 *** |