Java SDK @Id field cannot be null or empty

I have a problem when I want to add document using Java SDK, I get the following error: “The @Id field cannot be null or empty.” I don’t understand why because my Document Entity class inherits ID field with @Id annotation from super class…

Is this using Spring Data or the like? Maybe you can paste or link to a short code sample that demonstrates the problem.

The error appears to come from the KeyValueLocator class and is accurate. If it’s null/empty, somehting either is failing to set it or clearing it. You might examine from that exception with a debugger to figure out what’s going on.

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.

Ah, it’s using the repository, which as you probably know from the javadoc is marked volatile/experimental. That looks like a bug to me.

I’ve filed JCBC-1158 to investigate. You can track it there.