Hello,
I have a db model class that extends from a base class so we are using SuperBuilder on it. The model has fields with @Id and @Version annotations, which should be filled by MongoDB on insert. Since we're trying to keep the models immutable, everything is final. The right thing seems to be to add the @With annotation so Mongo can update the fields (create a copy with the id/version fields set). Using both @With and @SuperBuilder causes build errors. I've tried putting @With on the class and on the individual fields, with same error resulting.
Anyone got any ideas how to make this work? Our current (undesirable) workaround is to just make the fields mutable.
Thanks in advance,
Mike
Example class
@Getter
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@Document(collection = "examples")
@With
public class ExampleDocument extends CommonDataModel {
@Id private final ObjectId id;
@Nonnull private final String field1;
@Nonnull private final String field2;
@Version private final Long version;
}
Example error:
error: constructor ExampleDocument in class ExampleDocument cannot be applied to given types;
@Id private final ObjectId id;
^
required: ExampleDocumentBuilder<?,?>
found: ObjectId,String,String,Long
reason: actual and formal argument lists differ in length