在Grails中,如果我这样做:
domainObj.save(failOnError: true)
也会隐式刷新Hibernate的缓冲区,就像将“flush:true”添加到args一样吗?如果可以的话,请提供可靠的消息来源,谢谢。
最佳答案
根据AbstractSavePersistentMethod中的代码,验证发生在保存/刷新之前,因此,如果验证失败并且failOnError为true,则将抛出ValidationException,并且不会发生刷新。
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
关于grails - Grails的failOnError是否会强制刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22394942/