Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 对象化删除不';我好像不工作_Google App Engine_Google Cloud Endpoints_Objectify - Fatal编程技术网

Google app engine 对象化删除不';我好像不工作

Google app engine 对象化删除不';我好像不工作,google-app-engine,google-cloud-endpoints,objectify,Google App Engine,Google Cloud Endpoints,Objectify,我试图使用objectify从数据存储中删除一个实体,但即使在关闭实例并重新启动它之后,该实体似乎也没有被删除。这是实体在数据存储中的外观(在生产服务器和开发服务器上时): 这是我用来尝试删除它的代码: @ApiMethod(name = "deleteDataVersion") public Result deleteDataVersion(@Named("id") String id) { // Where id is the id of the entity in the da

我试图使用objectify从数据存储中删除一个实体,但即使在关闭实例并重新启动它之后,该实体似乎也没有被删除。这是实体在数据存储中的外观(在生产服务器和开发服务器上时):

这是我用来尝试删除它的代码:

@ApiMethod(name = "deleteDataVersion")
public Result deleteDataVersion(@Named("id") String id) {

    // Where id is the id of the entity in the datastore.

    if (id != null && !id.equals("")) {
        ofy().delete().type(DataVersion.class).id(id).now();
        return new Result(Result.STATUS_SUCCESS);
    } else
        return new Result(Result.STATUS_FAILED);
}
我还尝试了以下代码:

@ApiMethod(name = "deleteDataVersion")
public Result deleteDataVersion(@Named("id") String id) {

    if (id != null && !id.equals("")) {

        // DataVersion doesn't have a parent.
        Key<DataVersion> key = Key.create(null, DataVersion.class, id);

        ofy().delete().key(key).now();
        return new Result(Result.STATUS_SUCCESS);
    } else
        return new Result(Result.STATUS_FAILED);
}

我似乎找不到问题:(任何帮助都将不胜感激!我确信这是我忽略的次要问题(对于Objectify/AppEngine来说是相当新的)。

端点中参数中的ID是一个字符串,您尝试删除ID较长的对象DataVersion

ofy().delete().type(DataVersion.class).id(Long.valueOf(id)).now();
会更好!

先拿钥匙。
Key=Key.create(null,DataVersion.class,id);

然后使用键从数据库中获取实体。
DataVersion DataVersion=ofy().load().key(key).now();

然后使用objectify删除实体。

of y().delete().entity(dataVersion).now();

id可以是字符串或长字符串,但“请注意,数字id和字符串id并不等效;123和“123”是不同的id。”
ofy().delete().type(DataVersion.class).id(Long.valueOf(id)).now();