简体   繁体   中英

Storing a reference to a Blob in a Entity

Im trying to put a blob key into a property of an entity and Im receieving the following error:

/api/get/tmr
java.lang.IllegalArgumentException: The string property st has a value that is too long. It cannot exceed 500 characters.

My Code is:

BlobKey k;
k=BlobUtil.pBE(d,DT,"st");
DT.setProperty("count",count);
Object O;
O = DT.getProperty("st");
String cl = O.getClass().getName();
String Cl = O.getClass().getCanonicalName();
log.info(" st property |"+DT.getProperty("st")+"|"+cl+"|"+Cl+"|");
datastore.put(DT);

The error is comming from the last line:

TMComputation TMR:  st property |<BlobKey: AD8BvulOBPut_iHAT4caaMyjl_X0qhnd5gT7IIP-UI-Q7wuY-XS2kuT1yzKWUo98M9YA5dld_3LG7CEAIER5La6x-Gz7zAAmnlGakhgHydkIFAujBYZ3ffRtya3ECcehqlHQDYdyqQVeS2ZmtbpfL4hUT3pTNiBCwJOIeFjO2qZGDycVSe_VJIddH87vuyH2R0ZrU_jxDtLEJ2pbtVaxnC96AS8BBSTzlKtNVjNilfNAUydmDwXqknmN4jOZLIPKhivUnv_ohEHjWo8J-CJsvHZcZQnqoIQBR9yF6JvWHWqxbkMDSvUkePAYXywcsziNn2t76dVh8jKnSGAQkU2FbufgMBKkSCASakcnpz76P8RHWn3VcYyflHQXLSXNLUmuiK-yPv9QR6NXGQ8Uyy2v4Bl9JzHP5v1PnzJDCc3Zwj9ytMeww7K_nyQuXJZw9J8oQpSitXSKmdqHVQHvbtSxFzZmlU59WyEwYgoW1ID0nRpiYwh30QrIXAQrm0AHdcN-ji_D44xSmP4dm3eFZQ2iglRz-71C_Wanbw7ZYmMrNge7qErHaemeIBXePWx5tLdN7jfaLBA2ho3V6_o2yI2dFseVxzGMfle23GTuSusvuzBA_DfJYFyFjVj0htMCbadMyr3UoP2umPHFPA-F-oD2o5i7tsLkjoIAWV5njbBsPtUYq3_66r1jomE3bbEYnV5KvnM4vEEyd2g_1_XCg-476vB9AaKoaxLQfZWPL5pLu5mIqXJYIcimUzOoxLH6deEmU08N7476CjjpouIMPdlRxCu_HBsf_0LMLrkQpuRmLxq5Z-lhtfEfYdAUFdSZfa-evaGw8EzVitAe1RaUrnbTv8p-TySJG-H4zrHslv-84PY4grKsNsCTALC0ogCFbCAmyplQikYGYG0Z08bq7RSDvBfcfKJwAcTHCkbkQ9aIId3nKP8LfNzTwR3DsofBrT5xcyJULZoARwktmT13-L_qUUHwtzz4Wt5Z7A>|com.google.appengine.api.blobstore.BlobKey|com.google.appengine.api.blobstore.BlobKey|

This shows that the st property contains a blob key and not a string.

As per the documentation, if you are using a Java type String and the value exceeds 500 characters, then an IllegalArgumentException is thrown.

The workaround to this is to use a Text string (long) ie com.google.appengine.api.datastore.Text instead of java.lang.String . This data type can hold information upto 1MB but keep in mind that it is not indexed.

Check out the documentation on "Properties and value types" at https://developers.google.com/appengine/docs/java/datastore/entities

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM