Reputation: 1265
Immediately before validate and save I check my domain object:
class MyDomain ... {
static belongsTo = [owner: AnotherClass]
...
}
The 'owner' is set correctly. Then I validate; it passes. Then I save; it throws an exception about order_id being null. It throws even if use failOnError:false
in save
.
This happens in an integration test.
Any ideas?
Upvotes: 2
Views: 866
Reputation:
Even if your instance is valid according to the constraints the save can fail, because it depends on the database. Imagine if you have:
class Person {
...
Integer age
...
static constraints = {
age nullable: true
}
}
And an instance:
def person = new Person(age: 9999)
And in your database table the age of person can have as max value 999. Your instance is valid, but the insert will throw an error.
The same can happen with foreign keys and operations that depends on triggers.
Upvotes: 2