|
I have 2 domain objects, A and B. A has a B property and B belongsTo A.
If the B object validation fails when editing an A, it fails silently. The fields that fail validation simply revert to their old values. Based on this, it appears that belongsTo isn't working properly in Grails 2.0 (we didn't have this problem with Grails 1.3.7 ). If anyone is aware of a workaround I'd appreciate it. I'm currently on Grails 2.0.1 |
|
i think i remember seeing something in the documentation that if a object fails validations, then any save will normally fail quietly and the object is discarded.
There is an option on the .save(failOnErrors : true ) - which would allow you trap the fail with an exception. otherwise you can call .validate () on the object and check .hasErrors(), and call .getErrors() to process /review them and fix before you save. see this http://grails.org/doc/2.0.x/ref/Domain%20Classes/save.html i hope that helps |
|
Thanks Will but that still doesn't explain why this works in Grails 1.3.7 but not in Grails 2.0.
I seem to remember reading that Grails 2.0 is using a stricter version of Hibernate that Grails 1.3.7 so I'm wondering if this may be causing the problem. Has anyone else had any problems with one-to-one relationship validation with the stricter version of Hibernate or is just affecting me? |
|
again somewhere in the documentation it says there was a chnage in behviour - where the validation would fail but the vlaues would still be wrriten in 1.3.7 - and i i believe v2 declared as an erroneous behaviour -
you should not persist values known to have failed validation - hence the change in behaviour |
|
I think you must be misunderstanding my question. I realize that you don't want to persist values that fail validation. My point is that in a one-to-one relationship in Grails 1.3.7, if the ownee class (the class with the belongTo in it) fails validation when saving the owner class, an error is thrown, which can then be displayed to the user so he is aware of it. With Grails 2.0, however, if the ownee class fails validation when saving the owner class, the validation fails silently in that the fields where the validation failed simply revert to their old values.
This seems like a pretty big bug to me. |
|
Please attach an example to a JIRA that reproduces the problem.
-- Graeme Rocher On Thursday, February 23, 2012 at 1:22 AM, Jeff wrote:
|
| Powered by Nabble | Edit this page |
