Java访问Azure Table Storage:无法获取PK/RK外的实体属性值
解决Azure表存储无法获取自定义属性值的问题
问题根源
你的ImportantData实体类存在两个关键问题:
- 自行定义了
PartitionKey和RowKey字段,而父类TableServiceEntity已经内置这两个属性,重复定义会导致SDK序列化/反序列化逻辑冲突。 - 自定义字段
AssociatedData1使用默认包访问权限,不符合Azure表存储SDK的JavaBean序列化要求,SDK无法正确识别并赋值。
修正后的实体类
移除重复主键字段,将自定义字段改为私有,并通过父类构造方法初始化主键:
public class ImportantData extends TableServiceEntity { private String AssociatedData1; public ImportantData(String partitionKey, String rowKey, String associatedData1) { super(partitionKey, rowKey); this.AssociatedData1 = associatedData1; } public ImportantData() { super(); } public String getAssociatedData1() { return AssociatedData1; } public void setAssociatedData1(String associatedData1) { AssociatedData1 = associatedData1; } }
特殊场景处理
如果Azure表中的属性名和实体类字段名存在大小写差异,可通过@Property注解明确映射:
@Property(name = "associatedData1") private String AssociatedData1;
验证效果
修改实体类后重新执行查询代码,控制台将输出预期结果:
true MMBI | 12345678
内容的提问来源于stack exchange,提问作者Jrdan
相关产品推荐
相关产品推荐

