问题
I have two simple domain classes:
class Name {
String firstName
String lastName
static belongsTo = [person: Person]
}
class Person {
Name name
String comment
}
and service with two methods:
class PersonService {
Person newPerson() {
def person = new Person()
person.name = new Name()
person
}
Person savePerson(Person person) {
person.save()
}
}
Now if I create a new Person
with PersonService.newPerson()
and then try to save it using savePerson()
method using grails 1.3.7 everything works fine. With grails 1.4.0 or 2.0.0.M2 exception is thrown
Column 'name_id' cannot be null
Is this a bug in new grails? Or maybe there is something wrong with my code?
Test method:
void testPersonSave() {
def person = personService.newPerson()
person.name.firstName = 'f'
person.name.lastName = 'l'
person.comment = 'comment'
personService.savePerson(person) //throws an exception
}
回答1:
Looks like a bug. Please JIRA: http://jira.grails.org/ .
来源:https://stackoverflow.com/questions/7387745/grails-2-0-0-m2-cascade-save-problem