猿问

Azure 插入不添加实体的新属性 (Java)

我有一个带有 Azure 表存储的数据库,我在其中存储具有各种属性的实体,并且一切运行良好。但是,当我尝试添加新属性时,它根本没有被存储。我的 InsertEntity 代码如下所示:


LunchDateEntity entity = new LunchDateEntity(ID);

try{


AppStorage storage = new AppStorage(TABLENAME);

entity.setProperty1(prop1)

entity.setProperty2(prop2)

entity.setProperty3(prop3)


entity.setNewProperty(newProp)


TableOperation operation = TableOperation.insert(entity);

m_table.execute(operation);

catch(...) {...}

Prop 1,2,3 是我以前拥有的实体,它们被添加到表存储中,但是,newProp 根本没有在表存储中显示。


我尝试在构建实体时对该属性进行硬编码,但无济于事。


我的实体类看起来像:


public class myEntity extends TableServiceEntity {

public static final String TABLENAME = "myTable";

public static final String PARTITION_KEY = "part1";


public String m_prop1 = "";

public String m_prop2 = "";

public String m_prop3 = "";

public String m_newProp = "";


public myEntity() {

 this.partitionKey = PARTITION_KEY;


public void setProp1(String prop1) {

  m_prop1 = prop1;

}


public String getProp1() {

 return m_prop1;

}


public void setNewProp(String newProp) {

 m_newProp = newProp;

}

对于所有属性,依此类推。他们都长得很像。


我是否误解了插入功能的工作原理?有什么想法为什么这不起作用?


提前致谢


牛魔王的故事
浏览 179回答 1
1回答

Qyouu

根据我的测试,我认为这是因为名称规则。我测试了添加 newProp 或 newProp1 字段,与您的解决方案相同。新房没有出现。然后我尝试添加姓名、电话或什至 oldProp,一切正常。功能代码:@FunctionName("addentity")    public String addentity(@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) String req,                            ExecutionContext context) {        String storageConnectionString =                "***";        String jsonStr = "insert failed";        try {            // Retrieve storage account from connection-string.            CloudStorageAccount storageAccount =                    CloudStorageAccount.parse(storageConnectionString);            // Create the table client.            CloudTableClient tableClient =                    storageAccount.createCloudTableClient();            // Create a cloud table object for the table.            CloudTable cloudTable = tableClient.getTableReference("test");            // Create a new customer entity.            myEntity entity = new myEntity("jay1","gong");            //entity.setProp1("a");            entity.setNewProp("new");            entity.setOldProp("old");            //entity.setNewProp1("new1");            //entity.setName("kkkkk");            // Create an operation to add the new customer to the people table.            TableOperation insertEntity =                    TableOperation.insert(entity);            // Submit the operation to the table service.            cloudTable.execute(insertEntity);            jsonStr = entity.toString();        } catch (Exception e) {            // Output the stack trace.            e.printStackTrace();        }        return jsonStr;    }我的实体:package com.fabrikam.functions;import com.microsoft.azure.storage.table.TableServiceEntity;public class myEntity extends TableServiceEntity {    public String m_prop1 = "";    public String m_newProp = "";    public String m_newProp1 = "";    public String name = "";    public String oldProp = "";    public myEntity(String lastName, String firstName) {        this.partitionKey = lastName;        this.rowKey = firstName;    }    public void setProp1(String prop1) {        m_prop1 = prop1;    }    public String getProp1() {        return m_prop1;    }    public String getNewProp(String newProp) {        return m_newProp;    }    public String getNewProp1(String newProp1) {        return m_newProp1;    }    public void setNewProp(String newProp) {        m_newProp = newProp;    }    public void setNewProp1(String newProp1) {        m_newProp1 = newProp1;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getOldProp() {        return oldProp;    }    public void setOldProp(String oldProp) {        this.oldProp = oldProp;    }}输出:我认为'newProp'Azure 表存储保留了类似的内容,您可以调整名称规则,然后一切都会好起来的。我做进一步的测试:只是为了总结,最后,这完全是关于我的 getter 和 setter 的错误格式。我们需要检查对象定义。
随时随地看视频慕课网APP

相关分类

Java
我要回答