
[英]OneToOne mapping JPA - Cascade.All not copying the id column
[英]Spring DATA JPA onetoone unidirectional mapping CASCADE.ALL insert duplicate child row, not update
我正在编写一个实体 class 结果,它有一个到另一个实体 UpstreamResult 的 ONETOONE 映射。 当我执行 save() 方法时。 在 spring 启动并发情况下,有时,子实体插入未更新并抛出 JdbcSQLIntegrityConstraintViolationException:唯一索引或主键违规
父 Class:
@Table(name = "RESULT")
public class Result implements Serializable {
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "UPSTREAMSIGNALTESTRESULT_ID", referencedColumnName = "uuid", unique=true)
private UpStreamTestResult upStreamSignalTestResult;
...
儿童 Class:
@Table(name = "UPSTREAMTESTRESULT")
public class UpStreamTestResult implements Serializable {
@Id
private String uuid;
@Override
public boolean equals(Object o) {
if (!(o instanceof UpStreamTestResult)) {
return false;
}
UpStreamTestResult that = (UpStreamTestResult) o;
if (this == that) {
return true;
}
return this.getUuid().equals(that.getUuid());
}
@Override
public int hashCode() {
return this.getUuid().hashCode();
}
.....
如果我运行我的应用程序一次,它工作正常。 但是当我运行我的应用程序 aync 和高并发,并且所有实例都连接到一个数据库时,它会抛出上述异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.