Hibernate grails无错误并验证true,但不保存。休眠不更新
grails无错误并验证true,但不保存 我有一个调用.save()的方法,但没有将数据保存在数据库中。我试过ff:Hibernate grails无错误并验证true,但不保存。休眠不更新,hibernate,grails,gorm,Hibernate,Grails,Gorm,grails无错误并验证true,但不保存 我有一个调用.save()的方法,但没有将数据保存在数据库中。我试过ff: 调用FailOnError:true,但不显示任何失败的内容 validate(),它确实返回true hasErrors(),它确实返回true put 放置returnobjectinstance并显示值已更改 设置齐平:false 但是,在上面所有这些没有显示任何验证失败的情况下,它仍然不会保存在数据库中。我尝试记录hibernate,但它没有显示该实例的“update”
def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
.....
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
if (params.created) {
flash.message = "OBP Case has been successfully saved."
}
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
flow.appDate = caseInstance.applicationDate
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
// get the following list to populate dropdown fields
def residenceTypeList = ResidenceType.list()
def visualImpairmentCauseList = VisualImpairmentCause.list()
def referralSourceList = ReferralSource.list()
[residencesType: residenceTypeList, visualImpairmentsCause: visualImpairmentCauseList, referralSources: referralSourceList]
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
if (params.created) {
flash.message = "OBP Case has been successfully saved."
}
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
flow.appDate = caseInstance.applicationDate
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
// get the following list to populate dropdown fields
def residenceTypeList = ResidenceType.list()
def visualImpairmentCauseList = VisualImpairmentCause.list()
def referralSourceList = ReferralSource.list()
[residencesType: residenceTypeList, visualImpairmentsCause: visualImpairmentCauseList, referralSources: referralSourceList]
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
....
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
这是我的保存服务代码
def CmCase saveUpdateCase(CmCase caseInstance, Users currentUser) {
if (!caseInstance.save(flush:true)) {
if (log.isDebugEnabled()) {
caseInstance.errors.allErrors.each { log.debug it }
}
throw new CaseException(message: "case.cmCase.exception", caseInstance: caseInstance)
}
return caseInstance
}
Hibernate在执行其他查询时显示所有select和insert,但不显示update 更新:我发现当我在保存之前再次调用objectInstance.get(id)时,它现在正在保存。但我为什么要重新得到它?这是一种行为吗?如果是,请卸下
CmCase
。如果是服务方法,请删除def
。是否将正确的对象传递到saveUpdateCase
?对象从何处获取?我可以通过将.read()方法更改为.get在保存之前和之后进入控制器(当它重新进入查看模式时)来解决此问题。问题消失了,但在单击“取消”按钮时生成了另一个错误,该错误为null瞬态。因此,我必须做一个变通,通过将objectInstance存储在流中,将旧值分配给objectInstance。从数据库中获取新数据不会像我获取数据时那样有效,它会获取“脏”数据。我仍然对解决方案不满意,但这是我现在能想到的解决方案。我已经修改了代码以获得更清晰的视图。