Question

In Grails if I do:

domainObj.save(failOnError: true)

will that implicitly flush Hibernate's buffer as well, as if "flush:true" were added to the args? If you can please provide a credible source for your answer, thanks.

Was it helpful?

Solution

According to the code in AbstractSavePersistentMethod the validate occurs before the save/flush, so if it fails and failOnError is true, the ValidationException will be thrown and no flush will occur.

if (errors.hasErrors()) {
  handleValidationError(domainClass,target,errors);
  boolean shouldFail = shouldFail(application, domainClass);
  if (argsMap != null && argsMap.containsKey(ARGUMENT_FAIL_ON_ERROR)) {
    shouldFail = GrailsClassUtils.getBooleanFromMap(ARGUMENT_FAIL_ON_ERROR, argsMap);
  }
  if (shouldFail) {
    throw new ValidationException("Validation Error(s) occurred during save()", errors);
  }
  return null;
}
...
return performSave(target, shouldFlush); //here flush can happen
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top