本文介绍了休眠自动版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个客户维护应用程序。用户可以通过网页界面改变客户的详细信息。我想处理以下情况:
I have developed a customer maintenance application. Users can alter the customer details via web interface. I want to handle the following scenario:
-
用户1
加载customer1
详细信息。 -
用户2
加载customer1
详细信息。 -
用户1
更改并保存customer1
的name
。 -
用户2
只更改并保存customer1
的年龄。
User 1
loadscustomer1
details.User 2
loadscustomer1
details.User 1
changes and savescustomer1
'sname
.User 2
only changes and savescustomer1
's age.
在上面的场景中,最后数据库保存客户1
的旧名称和新时代,因为用户2
覆盖用户1
的更新。我正在使用Hibernate。我听说Hibernate自动版本控制支持这一点。如果有人知道如何处理这个问题,请告诉我。
In the scenario above, finally database holds customer1
's old name and the new age because User 2
overwrites User 1
's update. I'm using Hibernate. I had heard that Hibernate Automatic Versioning supports this. If any one know how to handle this please advise me.
推荐答案
您只需添加一个用<$ c $注释的字段c> @Version :
public class Customer {
@Id
private Long id;
@Version
private Long version;
// rest of the fields, etc.
}
阅读文章以获取更多信息。
Read this article for more information.
这篇关于休眠自动版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!