0

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

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 实体则不会。我做错了什么还是这是标准行为,我应该在保存之前检查关联的实体?谢谢你。

问候,洛伊扎

4

0 回答 0