Dgraph4j 20.03.0 is incompatible with dgraph 20.03.0 (and likely other 20.x.x versions)

I have an issue with setting value to UID predicate with NQuads using dgraph4j 20.03.0

Caused by: io.grpc.StatusRuntimeException: UNKNOWN: Input for predicate "Sector.parent" of type uid is scalar. Edge: entity:368 attr:"Sector.parent" value_type:STRING 

Code that sets this field looks like this:

addSetNQuad(mutation, subject, "Sector.parent", true, uids.get(parentId));
private void addSetNQuad(Mutation.Builder mutation, String subject, String predicate, boolean isUid, Object... values) {
  for (var value : values) {
    var value_ = Value.newBuilder();
    if (value == null) {
    } else if (isUid) {
       value_.setUidVal(Long.parseUnsignedLong(((String) value).substring(2), 16));


It looks like this happens due to mismatch in ValTypes enum in api.proto between dgraph4j (build.gradle fetches dgo’s file) dgo/api.proto at master · dgraph-io/dgo · GitHub and pb.proto used by dgraph itself dgraph/pb.proto at master · dgraph-io/dgraph · GitHub

I’ve also tried to add this mutation using JSON format:

if (uids.containsKey(parentId)) {
  String json = "{\"uid\": \"" + subject + "\", \"Sector.parent\": {\"uid\": \"" + uids.get(parentId) + "\"}}";

And it works fine like that, but it’s rather inconvenient (and wouldn’t allow me to add multiple references since json is replaced each time method is called)

The two proto files are not related. api.proto in dgo is the one used by clients to communicate with dgraph. pb.proto in dgraph is used by dgraph for its internal comm between alphas.

The issues you are facing is because of this:

For uids, you should use setObjectId(string uid) instead of setObjectValue. For anything else, you would use setObjectValue.

Thanks for explanation, works with this change (I’ve however already converted all insertions to just use Jackson.writeValue(...) followed by Mutation.setSetJson(...) as it’s easier to read this way).

When ObjectValue::setUidVal is used, just out of curiocity?

I was wondering the same and investigating :sweat_smile:. Till now it seems like stale code, but I will find out fully and let you know.

So, it is not being used. There is no switch case for this here: dgraph/mutation.go at master · dgraph-io/dgraph · GitHub