我有一个像这样定义的Contract类:
@Document
public class Contract {
@Id
private String id;
@Indexed(unique = true)
private String ref;
private String status = "pending";
// getter & setter & hashcode & equals & tostring...
}
我希望随着时间的推移保存合同状态,所以我创建了一个这样的Version类:
@Document
public class Version {
@Id
private String id;
private Contract contract;
private Instant createdAt;
// getter & setter & hashcode & equals & tostring...
}
当我尝试多次保存版本对象时,我有一个重复的键异常.我认为这是合约裁判的重复关键索引,在这里抱怨.
我怎样才能做到这一点?
最佳答案
只需添加@Reference,如下所示:
@Document
public class Version {
@Id
private String id;
@Reference
private Contract contract;
private Instant createdAt;
// getter & setter & hashcode & equals & tostring...
}