mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

Cannot update Domain objects with one-to-many relationships #69

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a contact domain object with one-to-many relationship to phone 
numbers. 
2.Create a new contact with one phone number and save it.
3. Implement JSON binding fix described at 
dalelotts.com/software-architect/grails
4. Get JSON representation of Contact.
5. PUT JSON back to server to update instance - this can be the same JSON or 
you can modify it.
6. A "A collection with cascade="all-delete-orphan" was no longer referenced by 
the owning entity instance" exception is thrown.

What is the expected output? What do you see instead?
I expected a successful update.

The exception is the result of the 'obj.properties = dto.properties ' in the 
service update. Before this assignment the phone number list in obj is a a 
PersistantList tracked by Hibernate. The phone number list in dto is an array 
list. The assignment of the properties from the DTO causes hibernate to lose 
track of the list.  

This is best solved by setting the properties from the map created in the 
DomainObjectReader as described in dalelotts.com/software-architect/grails.  

Is there some way to redefine the update method to 'def update(Map map)'?  This 
will fix the issue because property assignment from a properly generated 
parameter map will not overwrite/replace the PersistantList.

Alternatively, one could work around this issue by converting the dto to a 
valid parameter map and then then set the properties on obj. 

Any suggestions for alternative fixes would be appreciated.

What version of the product are you using? On what operating system?
0.6

Please provide any additional information below.

Original issue reported on code.google.com by dale.lotts on 24 Aug 2012 at 5:17

GoogleCodeExporter commented 8 years ago
Actually, the work around of converting the dto to a valid parameter map and 
then then set the properties on obj will not work as the VERSION of the object 
is lost.

From what I can tell, the VERSION of the domain object is always lost when 
using the API from this plugin.

Original comment by dale.lotts on 24 Aug 2012 at 5:42