Grails 2.0.0.M2 - cascade save problem

不问归期 提交于 2019-12-24 03:29:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!