I have abstract class which contains all common properties in my model:
import com.couchbase.client.java.repository.annotation.Id;
import com.fasterxml.jackson.annotation.JsonProperty;public abstract class AbstractEntity implements Entity {
@Id @JsonProperty(ID_ATTRIBUTE) private String id; @JsonProperty(REVISION_ATTRIBUTE) private String rev; private String ownerId; private DocumentType type;
}
And multiple classes that extend AbstractEntity, like BrandEntity for example:
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class BrandEntity extends AbstractEntity implements Brand {private String name; private String description; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public String getDescription() { return description; } @Override public void setDescription(String description) { this.description = description; }
}
But when I try to save entity for example:
System.out.println(entity.getId());
EntityDocument(Brand)* entityDoc = EntityDocument.create(entity);
EntityDocument(Brand)* newDocument = bucket.repository().insert(entityDoc);
*<> are not showing text inside
ID is printed and the exception is thrown:
BRAND::000d754b-af3a-4f55-8c7c-92db2a913ad9
RepositoryMappingException “The @Id field cannot be null or empty.”
Which is not true because I checked the value in debugger and printed it in the console.