I have a Contract class defined like this:
@Document
public class Contract {
@Id
private String id;
@Indexed(unique = true)
private String ref;
private String status = "pending";
// getter & setter & hashcode & equals & tostring...
}
I want to save contract state over time, so I created a Version class like this:
@Document
public class Version {
@Id
private String id;
private Contract contract;
private Instant createdAt;
// getter & setter & hashcode & equals & tostring...
}
When I try to save multiple times the version object over time, I have a duplicate keys exception. I think it's the duplicate key index on contract's ref which complains here.
How can I achieve this kind of thing?
Simply add @Reference like this:
@Document
public class Version {
@Id
private String id;
@Reference
private Contract contract;
private Instant createdAt;
// getter & setter & hashcode & equals & tostring...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With