【问题标题】:What can cause a Grails GORM save to fail after validate succeeds?验证成功后,什么会导致 Grails GORM 保存失败?
【发布时间】:2013-03-27 20:26:35
【问题描述】:

在验证和保存之前,我检查了我的域对象:

class MyDomain ... {
    static belongsTo = [owner: AnotherClass]
    ...
}

“所有者”设置正确。然后我验证;它通过了。然后我保存;它抛出一个关于 order_id 为空的异常。即使在save 中使用failOnError:false 也会抛出。

这发生在集成测试中。

有什么想法吗?

【问题讨论】:

标签: validation grails save grails-orm


【解决方案1】:

即使您的实例根据约束条件是有效的,保存也可能会失败,因为它依赖于数据库。想象一下,如果你有:

class Person {
  ...  
  Integer age
  ...
  static constraints = {
    age nullable: true
  }
}

还有一个实例:

def person = new Person(age: 9999)

在你的数据库表中,人的年龄可以有最大值999。您的实例有效,但插入会引发错误。

外键和依赖于触发器的操作也会发生同样的情况。

【讨论】:

    猜你喜欢
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多