grails hiberate discard()被忽略了(grails hiberate discard() being ignored)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
grails hiberate discard()被忽略了(grails hiberate discard() being ignored)

我有一个修改和实例然后链接到另一个动作的动作。 如果实例上有错误,我想忽略我所做的更改。 但是,discard()方法不起作用。 状态更改始终保持不变。 我究竟做错了什么?

def reject={ def notice=Notice.get(params['id']); if(!notice){ flash.message="Could Not Find Notice With ID:"+params.id; redirect(action:'list'); return; } flash.messages=[:]; flash.errors=[:]; notice.status=NoticeType.REJECTED; if(!notice.hasErrors() && notice.save(flush:true)){ //success message flash.messages.notice_tab=["Notice Was Successfully Flagged As Rejected"]; } } else{ //error message flash.errors.notice_tab=[]; notice.errors.allErrors.each{ flash.errors.notice_tab.push(it); } notice.discard(); //THIS DOES NOTHING???? } chain(action:'edit', id:params['id'] ) return; }

我也试过notice.refresh()将值设置回原始值。 没关系。 仍然坚持我设定的新价值观。 我将链改为重定向,同样的事情发生了。

I have an action which modifies and instance and then chains to another action. If there are errors on the instance I want to ignore changes I have made. However, the discard() method doesn't work. The status change is always persisted. What am I doing wrong?

def reject={ def notice=Notice.get(params['id']); if(!notice){ flash.message="Could Not Find Notice With ID:"+params.id; redirect(action:'list'); return; } flash.messages=[:]; flash.errors=[:]; notice.status=NoticeType.REJECTED; if(!notice.hasErrors() && notice.save(flush:true)){ //success message flash.messages.notice_tab=["Notice Was Successfully Flagged As Rejected"]; } } else{ //error message flash.errors.notice_tab=[]; notice.errors.allErrors.each{ flash.errors.notice_tab.push(it); } notice.discard(); //THIS DOES NOTHING???? } chain(action:'edit', id:params['id'] ) return; }

I also tried notice.refresh() to set values back to original. Didn't matter. Still persisted the new values I set. I changed the chain to a redirect and the same things happened.

最满意答案

一种解决方案是使用命令对象而不是域对象。 然后,在命令对象上成功完成验证后,您可以将值复制到域对象,然后保存以避免Hibernate丢弃。

One solution would be to use a Command Object instead of a Domain Object. Then once validation is done successfully on your Command Object you can copy the values to the Domain Object and then save to avoid the Hibernate discard.

更多推荐

本文发布于:2023-04-15 03:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/f454000dbefc4225eb024b418b3c400e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被忽略了   grails   hiberate   discard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!