java无法在Azure表实体中创建字节字段
我创建了一个扩展TableServiceEntity的实体类。我的类有一个名为Byte
类型的“value”字段:
public class TestEntity extends TableServiceEntity{
public Byte value;
public TestEntity(){
super("some_partition","somekey");
}
public Byte getValue() {
return value;
}
public void setValue(Byte value) {
this.value = value;
}
}
根据表服务实体的documentation,Byte
是受支持的字段类型之一
但是,当我尝试存储实体时,会出现以下异常:
java.lang.IllegalArgumentException: Type class java.lang.Byte is not supported.
at com.microsoft.azure.storage.table.EntityProperty.<init>(EntityProperty.java:175)
at com.microsoft.azure.storage.table.PropertyPair.generateEntityProperty(PropertyPair.java:271)
at com.microsoft.azure.storage.table.TableServiceEntity.writeEntityWithReflection(TableServiceEntity.java:217)
at com.microsoft.azure.storage.table.TableServiceEntity.writeEntity(TableServiceEntity.java:470)
at com.microsoft.azure.storage.table.TableEntitySerializer.writeJsonEntity(TableEntitySerializer.java:317)
at com.microsoft.azure.storage.table.TableEntitySerializer.writeSingleJsonEntity(TableEntitySerializer.java:411)
at com.microsoft.azure.storage.table.TableEntitySerializer.writeSingleEntityToStream(TableEntitySerializer.java:74)
at com.microsoft.azure.storage.table.TableOperation.insertImpl(TableOperation.java:389)
at com.microsoft.azure.storage.table.TableOperation.performInsert(TableOperation.java:370)
...
错误似乎出在EntityProperty构造函数(请参见source)上,它似乎不支持Byte
或byte
类型,仅支持Byte[]
和byte[]
:
protected EntityProperty(final String value, final Class<?> type) {
this.type = type;
this.value = value;
if (type.equals(byte[].class)) {
this.getValueAsByteArray();
this.edmType = EdmType.BINARY;
}
else if (type.equals(Byte[].class)) {
this.getValueAsByteObjectArray();
this.edmType = EdmType.BINARY;
}
...
我是做错了什么,还是这是一个文档错误
# 1 楼答案
这是一个documentation bug。正如Herve Roggero指出的,service model documentation表示不支持字节
# 2 楼答案
根据MSDN,Azure表服务允许的属性类型列表不包括Edm。字节,但不包括Edm。二进制(即字节[])。要更深入地了解允许的数据类型和其他限制,请参见Understanding the Table Service Data Model