我看到一个非常奇怪的行为,即将表实体保存在Azure存储表中。我的实体定义如下:
#File name is BatchJobRunTableEntity.java
package com.affinnova.batchJobs.db;
import com.microsoft.azure.storage.table.TableServiceEntity;
import groovy.json.JsonOutput;
import org.bson.types.ObjectId;
import java.util.Date;
import java.util.Map;
public class BatchJobRunTableEntity extends TableServiceEntity {
public BatchJobRunTableEntity(String jobId, String taskId) {
this.partitionKey = jobId;
this.rowKey = taskId;
}
public BatchJobRunTableEntity() {
}
public String accountId;
public String jobId;
public String taskId;
public String referenceKeys;
public String meta;
public String task;
public String batchServiceIdentifier;
public String clientGroupId;
public String state;
public String createdBy;
public String lastUpdatedBy;
public Date dateCreated;
public Date lastUpdated;
public void setAccountId(String accountId) {
this.accountId = accountId;
}
public String getAccountId() {
return this.accountId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobId() {
return this.jobId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public void setTaskId(ObjectId taskId) {
this.taskId = String.valueOf(taskId);
}
public String getTaskId() {
return this.taskId;
}
public void setReferenceKeys(String referenceKeys) {
this.referenceKeys = referenceKeys;
}
public void setReferenceKeys(Map referenceKeys) {
this.setReferenceKeys(JsonOutput.toJson(referenceKeys));
}
public String getReferenceKeys() {
return this.referenceKeys;
}
public void setMeta(String meta) {
this.meta = meta;
}
public void setMeta(Map meta) {
this.setMeta(JsonOutput.toJson(meta));
}
public String getMeta() {
return this.meta;
}
public void setTask(String task) {
this.task = task;
}
public void setTask(Map task) {
this.setTask(JsonOutput.toJson(task));
}
public String getTask() {
return this.task;
}
public void setBatchServiceIdentifier(String batchServiceIdentifier) {
this.batchServiceIdentifier = batchServiceIdentifier;
}
public String getBatchServiceIdentifier() {
return this.batchServiceIdentifier;
}
public void setClientGroupId(String clientGroupId) {
this.clientGroupId = clientGroupId;
}
public String getClientGroupId() {
return this.clientGroupId;
}
public void setState(String state) {
this.state = state;
}
public String getState() {
return this.state;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public String getLastUpdatedBy() {
return this.lastUpdatedBy;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Date getDateCreated() {
return this.dateCreated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public Date getLastUpdated() {
return this.lastUpdated;
}
}
我的应用程序在groovy中,我发现groovy类不能很好地与实体对象一起使用,因此我创建了一个Java类。现在,除“ referenceKeys”外的所有内容都存储在表中。最初我以为可能是数据,但是即使我将相同的数据设置为“ referenceKeys”,“ meta”,也只存储了meta,而referenceKeys却被拒绝了。我已经设置了调试点,以确保也设置了数据。
这里是一个例子:
BatchJobRunTableEntity batchJobRunTableEntityTmp = new BatchJobRunTableEntity("jobA", "taskA")
batchJobRunTableEntityTmp.setTaskId("taskA")
batchJobRunTableEntityTmp.setReferenceKeys(["keyA": "a", "keyB": "b"])
batchJobRunTableEntityTmp.setMeta(["keyA": "a", "keyB": "b"])
TableResult resultt = cloudTable.execute(TableOperation.insert(batchJobRunTableEntityTmp))
几乎就像在实体中甚至没有定义referenceKeys一样。
我在Java 7中并使用以下依赖项:'com.microsoft.azure:azure-storage:7.0.0'
更新 发现这是由于方法重载造成的,我有两种设置方法,一种用于字符串,另一种用于映射。如果我删除了map的重载方法,那么仍然有效,但仍然无法解释为什么它适用于“ meta”而不适用于“ referenceKeys”-轻微的颠簸但可行的事情。
#HAD TO REMOVE THESE METHODS
public void setMeta(Map meta) {
this.setMeta(JsonOutput.toJson(meta));
}
public void setReferenceKeys(Map referenceKeys) {
this.setReferenceKeys(JsonOutput.toJson(referenceKeys));
}
答案 0 :(得分:0)
发现这是由于方法重载造成的,我有两种设置方法,一种用于字符串,另一种用于map。如果我删除了map的重载方法,那么仍然有效,但仍然无法解释为什么它适用于“ meta”而不适用于“ referenceKeys”-轻微的颠簸但可行的事情。
#HAD TO REMOVE THESE METHODS
public void setMeta(Map meta) {
this.setMeta(JsonOutput.toJson(meta));
}
public void setReferenceKeys(Map referenceKeys) {
this.setReferenceKeys(JsonOutput.toJson(referenceKeys));
}
更新:
也必须删除此方法,在生产中对我不利。因此绝对不支持函数重载。
public void setTaskId(String taskId) {
this.taskId = taskId;
}