Grails 如何在创建域对象时设置版本属性?

Grails 如何在创建域对象时设置版本属性?,grails,gorm,Grails,Gorm,我正在尝试建立父母/子女关系的模型 我有以下域类: package test class Person { Person mother Person father String name static hasOne = [father: Person, mother: Person] static constraints = { name() father(nullable:true) mother(nullable:true) }

我正在尝试建立父母/子女关系的模型

我有以下域类:

package test
class Person {
Person mother
Person father
String name
static hasOne = [father: Person, mother: Person]
    static constraints = {
        name()
        father(nullable:true)
        mother(nullable:true)
    }   
    def Set<Person> children(){
        return Person.findAllByMother(this)
    }
}
版本参数应该在哪里生成?我认为这应该在save调用期间自动生成


更新:这个问题似乎与父/母关系有关,因为删除它并重新生成视图意味着元素可以持久化。

这个问题似乎与我试图在类中创建双向关系有关。事实上,这不是必需的。这是一种单向关系:人->父亲和人->母亲。相反的是在儿童项下计算的(我将扩展到包括父亲)

我的最后一节课是:

package test
class Person {
    int id
    Person mother
    Person father
    String name
    static constraints = {
        name()
        father(nullable:true)
        mother(nullable:true)
    }

    def Set<Person> children(){
         return Person.findAllByMother(this)
    }
}
包测试
班主任{
整数id
人母
人父
字符串名
静态约束={
姓名()
父(可空:真)
母亲(可空:真)
}
def Set children(){
返回人。findAllByMother(此)
}
}

我对Grails还是新手。

你能添加一段代码来处理新人的保存吗?没错,这应该是自动填充的。你试过“grails clean”吗?@David是的,我试过“grails clean”的各种组合。我解决了-见答案。
package test
class Person {
    int id
    Person mother
    Person father
    String name
    static constraints = {
        name()
        father(nullable:true)
        mother(nullable:true)
    }

    def Set<Person> children(){
         return Person.findAllByMother(this)
    }
}