【问题标题】:Google datastore with objectify getting MyClass is not a supported property type. exception使用 objectify 获取 MyClass 的 Google 数据存储不是受支持的属性类型。例外
【发布时间】:2014-04-25 12:41:19
【问题描述】:

我尝试存储自己使用 objectify 编写的类的对象。班级是:

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

@Entity
public class Group {

    @Id
    private Long id;
    private String name;
    private List<UserBalance> userBalanceList;

    //getters and setters for all fields
}

UserBalance 类是:

import org.joda.money.BigMoney;
import com.google.appengine.api.users.User;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

@Entity
public class UserBalance {

    @Id
    private Long id;
    private User user;
    @com.sappenin.objectify.annotation.Money
    private BigMoney money;

    //getters and setters for all fields
}

现在我得到的是:

com.googlecode.objectify.SaveException: Error saving mypkg.Group@1325bad7: 
       userBalanceList: mypkg.UserBalance is not a supported property type.
    at com.googlecode.objectify.impl.Transmog.save(Transmog.java:105)
    at ........

我在 objectify 服务中注册了 UserBalance 类。我使用自己的 OfyService 类来注册它们,如下所述:https://code.google.com/p/objectify-appengine/wiki/BestPractices#Use_Your_Own_Service

在我看来,我在 Group 类中的 userBalanceList 只是一个嵌入式实体,如下所述: https://code.google.com/p/objectify-appengine/wiki/Entities#Embedding_Entities

当我尝试将 UserBalance 对象单独存储(不作为组的一部分)时,它可以工作。 当我从 Group 类中删除 userBalanceList 字段时,它也可以工作。

怎么了?有人可以帮帮我吗?

【问题讨论】:

  • 您使用的是哪个版本的 Objectify?
  • 听起来像 v4。只有 v5 允许您像这样嵌入 @Entity 类。

标签: java google-app-engine google-cloud-datastore objectify


【解决方案1】:

您正在尝试将 Objectify v5 对象定义与 Objectify v4 一起使用。确保您的类路径中有正确的 Objectify jar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2022-12-16
    • 2019-03-17
    相关资源
    最近更新 更多