休眠自动版本控制 [英] Hibernate Automatic Versioning

查看:88
本文介绍了休眠自动版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个客户维护应用程序。用户可以通过网页界面改变客户的详细信息。我想处理以下情况:

I have developed a customer maintenance application. Users can alter the customer details via web interface. I want to handle the following scenario:


  1. 用户1 加载 customer1 详细信息。

  2. 用户2 加载 customer1 详细信息。

  3. 用户1 更改并保存 customer1 name

  4. 用户2 只更改并保存 customer1 的年龄。

  1. User 1 loads customer1 details.
  2. User 2 loads customer1 details.
  3. User 1 changes and saves customer1's name.
  4. User 2 only changes and saves customer1'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.

这篇关于休眠自动版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆