Google-cloud-java: com.google.cloud.datastore.DatastoreException: The value of property is longer than 1500 bytes

Created on 16 Sep 2016  路  3Comments  路  Source: googleapis/google-cloud-java

Hello,

I'm using the new google-cloud-datastore 0.3.0

I'm trying to write a json object into the datastore, this object can be larger than 1500 bytes.

This is my code:

Entity entity = Entity.builder(syncKey) .set("id", objId) .set("json_obj", Blob.copyFrom(objJson.toString().getBytes())) .set("status", "on_progress") .set("type", syncLocation) .set("started_at", DateTime.now()) .build(); datastore.put(entity);

And I'm getting this exception:
"Code: 3 Message: The value of property "json_obj" is longer than 1500 bytes. - com.google.cloud.datastore.DatastoreException: The value of property "json_obj" is longer than 1500 bytes.

I thought the blob object didn't have a 1500 bytes restriction.

Is it possible to specify with the API that this property should not be indexed?

datastore

Most helpful comment

Hi @ghorkov, thanks for the report!

Is it possible to specify with the API that this property should not be indexed?

Sure, you should be able to do that with:

Blob blob = Blob.copyFrom(objJson.toString().getBytes());
Entity entity = Entity.builder(key)
    .set("id", objId)
    .set("json_obj", BlobValue.builder(blob).excludeFromIndexes(true).build())
    .set("status", "on_progress")
    .set("type", syncLocation)
    .set("started_at", DateTime.now())
    .build();
datastore.put(entity);

Please let us know if this fixes your problem.

All 3 comments

Hi @ghorkov, thanks for the report!

Is it possible to specify with the API that this property should not be indexed?

Sure, you should be able to do that with:

Blob blob = Blob.copyFrom(objJson.toString().getBytes());
Entity entity = Entity.builder(key)
    .set("id", objId)
    .set("json_obj", BlobValue.builder(blob).excludeFromIndexes(true).build())
    .set("status", "on_progress")
    .set("type", syncLocation)
    .set("started_at", DateTime.now())
    .build();
datastore.put(entity);

Please let us know if this fixes your problem.

Thank you @mziccard it worked like magic :)

I am using API 2.0.0, what did you mean by Entity in here? How do i get its instance? Any recent resource on it?

Was this page helpful?
0 / 5 - 0 ratings