如果我这样做,请参阅Grails:
domainObj.save(failOnError: true)
是否会隐式刷新Hibernate的缓冲区,就好像将“flush:true”添加到args中一样?如果您能为您的答案提供可靠的来源,谢谢。
答案 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