Grails的failOnError会强制刷新吗?

时间:2014-03-14 02:19:01

标签: grails groovy persistence gorm

如果我这样做,请参阅Grails:

domainObj.save(failOnError: true)

是否会隐式刷新Hibernate的缓冲区,就好像将“flush:true”添加到args中一样?如果您能为您的答案提供可靠的来源,谢谢。

1 个答案:

答案 0 :(得分:4)

根据AbstractSavePersistentMethod中的代码,验证发生在save / flush之前,因此如果失败并且failOnError为true,则抛出ValidationException并且不会发生刷新。< / p>

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