I’m just starting with Grails, and here is the first issue.
I spent several hours to find out that domain object cannot be inserted in DB, until all its properties are populated.
class Item {
String title
String link
}
class ItemController {
def fetch = {
def item = new Item()
item.title = "blabla"
// no value for "link"
item.save()
}
}
Looks logical, but why is it skipped so silently? Can I configure something to get exceptions in such cases?
Thanks
No exception is thrown by default .
The
save()method injected to Domain classes returnsfalseif an error has occured during the validation phase.A classic code sample for checking save/update of a domain class is :
If you need to have an exception for a particular domain class, use:
and exceptions for validation failures will be thrown.
If you want to throw an exception for EVERY domain classes, then simply set
grails.gorm.failOnErrortotruein grails-app/conf/Config.groovyBe carefull : all domain properties have an implicit
nullable: falseconstraint.I recommend you reading this article.