Grails - 一对一关联的例外

时间:2012-05-21 14:18:26

标签: grails gorm

我在验证域类时遇到问题。我有两个以一对一关系关联的域名:

class AssemblyForm {
    Measures measures
    static hasOne = [measures: Measures]
}

class Measures {
    AssemblyForm assemblyForm
}

现在我绑定并在控制器和服务中创建它们:

// controller
class AssemblyFormController {
    def save() {
        AssemblyForm assemblyFormInstance = new AssemblyForm()
        assemblyFormInstance.measures = measures
        assemblyFormService.save(assemblyFormInstance)
    }
}

// service
class AssemblyFormService {

    public AssemblyForm save(AssemblyForm assemblyForm) {
        try {
            assemblyForm.save()
        } catch (Throwable t) {
        }
        return assemblyForm
    }
}

现在我希望assemblyForm实体在其关联有错误时不要保存在数据库中。但事实是,当Measures实体有一些错误时,AssemblyForm会持久保存到数据库,而Measures实体则不会。我做错了什么或这是标准行为,我应该在保存前检查相关实体?谢谢。

此致 Lojza

0 个答案:

没有答案