Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 2.0 final
-
Fix Version/s: 2.0.1
-
Component/s: Persistence
-
Labels:None
Description
Using your nose / face example for a one-to-one relationship, I created two classes:
class Face {
static hasOne = [nose: Nose]
}
class Nose {
Face face
}
What I expected to happen is when creating a Face object and assign a Nose object to it, both will be saved:
(1)
Face face = new Face()
Nose nose = new Nose()
face.nose = nose
face.save()
This isn't working, but this is:
(2)
Face face = new Face()
Nose nose = new Nose()
face.setNose(nose)
-- *NEW* --> nose.face = face
face.save()
And this (what I really don't understand):
(3)
Face face = new Face(nose: new Nose()).save()
I don't understand, why (3) works as expected, (1) is not. It seems, that because of the bidirectional one-to-one relation the nose object isn't valid (nose.validate() => false), because in (1) I did not assign the face to the nose object, as in (2), but in (3) this is done automatically.
Issue Links
| This issue duplicates: | ||||
| GRAILS-8337 | NULL not allowed for column when saving one to one |
|
|
|
| GRAILS-8451 | Transitative persistence for Many-to-one associations not cascading saves |
|
|
|
This issue is related to:
http://jira.grails.org/browse/GRAILS-8451