简体   繁体   中英

Does Grails's failOnError force a flush?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM