【问题标题】:Objectify - com.googlecode.objectify.SaveException: Error saving : id cannot be zeroObjectify - com.googlecode.objectify.SaveException:保存错误:id 不能为零
【发布时间】:2014-11-25 00:13:19
【问题描述】:

我在使用 Objectify 的 Google App Engine 项目中遇到以下错误:

[INFO] com.googlecode.objectify.SaveException: Error saving com.netbase.model.InsightDataSet@13b24628: id cannot be zero
[INFO]  at com.googlecode.objectify.impl.EntityMetadata.save(EntityMetadata.java:95)
[INFO]  at com.googlecode.objectify.impl.WriteEngine.save(WriteEngine.java:73)
[INFO]  at com.googlecode.objectify.impl.SaverImpl.entities(SaverImpl.java:60)
[INFO]  at com.googlecode.objectify.impl.SaverImpl.entity(SaverImpl.java:35)
[INFO]  at com.netbase.server.InsightManager.persistInsights(InsightManager.java:26)
[INFO]  at com.netbase.server.LongTestServlet.downloadAllInsightsAsTimeSeriesAndSend(LongTestServlet.java:140)
[INFO]  at com.netbase.server.LongTestServlet.doHelper(LongTestServlet.java:98)
[INFO]  at com.netbase.server.LongTestServlet.doPost(LongTestServlet.java:52)

这是我的 java 类的定义方式:

@com.googlecode.objectify.annotation.Entity
public class InsightDataSet {
    @com.googlecode.objectify.annotation.Id long id;

这是我尝试保存的方法:

    InsightDataSet insightDataSet = new InsightDataSet(username, topicId, requestDate);
    ofy().save().entity(insightDataSet).now();

【问题讨论】:

    标签: java google-app-engine objectify


    【解决方案1】:

    根据https://groups.google.com/forum/#!topic/objectify-appengine/aRRRQNILQb0,标有Objectify 注释@Id 的字段必须是Long 而不是long,以便Objectify 自动生成Java 对象的id。

    所以我将我的类定义更改为:

    @com.googlecode.objectify.annotation.Entity
    public class InsightDataSet {
        @com.googlecode.objectify.annotation.Id Long id;
    

    这解决了问题。

    【讨论】:

      猜你喜欢
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2012-10-01
      • 1970-01-01
      • 2013-10-03
      相关资源
      最近更新 更多