Reputation: 4742
If a domain class will validate can I be assured it will save (assuming nothing super-drastic like the database is down)? More explicitly, under which scenarios will an object pass validation but throw an error on save.
Upvotes: 2
Views: 530
Reputation: 187529
under which scenarios will an object pass validation but throw an error on save.
Domain class constraints can check anything, so if "the thing they check" changes between the calls to validate()
and save()
, then it's entirely possible that the former will succeed and the latter fails.
Here's a very simple such example
Book.ISBN
has a unique contraintmyBook.validate()
is called and passesmyBook
is savedmyBook.save()
fails because the unique constraint on ISBN now failsUpvotes: 3
Reputation: 19682
Save will throw an error if your database has additional constraints that don't allow the insert or update to succeed. If your database doesn't have any additional constraints and barring any sort of infrastructure outages, I can't think of any reason save()
would fail if validate()
is true.
Upvotes: 3