新接手的工程中,测试人员反应一个简单的保存功能,有时好用,有时就经常不成功,需要重试很多次才行。
我在仔细查看了原代码逻辑,没有发现什么问题,进行了本地测试,也没发现不成功的情况。
通过翻看正式环境的log,发现了有一些id重复的报错,原来是这个搞的。
原来的实体类的id注释是这么写的:
@GenericGenerator(name="generator", strategy="increment")
@Id
@GeneratedValue(generator="generator")
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}
详细解释可以看:http://articles.e-works.net.cn/pc_server/article101508.htm
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}