NHibernate 覆盖乐观场景下的并发
我已经针对并发情况实现了乐观锁定。 我已使用映射文件中的版本属性来链接到整数。
我的目标是,如果用户尝试保存过期的对象,她将可以选择覆盖更改。
我已经轻松地设法让 SaveOrUpdate 抛出异常,但是现在如何覆盖它,以便如果用户愿意,当前对象将覆盖现有的持久对象,同时仍然更新版本号,并且无需执行手动成员将变量明智地复制到非陈旧对象中?
这似乎是一个常规的逻辑场景,但我没有看到任何内置机制。那么这是一个反模式吗?
感谢您的帮助和见解。
亲切的问候
LJ
I have implemented optimistic locking for concurrency situations.
I have used the version property in the mapping files to link to a integer.
My aim is that if a user tried to save an out-of-date object, she will be given the option to overwrite changes.
I have easily managed to get the SaveOrUpdate to throw an exception, but how do I now override that so that if the user so wishes, the current object overwrites the existing persisted object, while still updating the version number, and without doing a manual member-wise copy of the variables into the non-stale object?
This seems like this is a regular logical scenario, but I don't see any built-in mechanism for this.So is this an anti-pattern?
Thanks for your help and insight.
Kind regards
LJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该研究一下 session.Merge 方法。
吉德
I think you should look into the session.Merge method.
Jide