Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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_Jpa_Enums_Google Cloud Datastore - Fatal编程技术网

Google app engine 谷歌应用引擎数据存储-枚举

Google app engine 谷歌应用引擎数据存储-枚举,google-app-engine,jpa,enums,google-cloud-datastore,Google App Engine,Jpa,Enums,Google Cloud Datastore,我正在尝试使用JPA将枚举保存并查询到Google App Engine数据存储中。 根据枚举,默认情况下是JPA持久数据类型。但我得到的是以下例外: com.xxx.utils.ActionLogUtils logCreateUserAction: actiontype: **com.xxx.endpoints.ActionLog$ACTION_TYPE** is not a supported property type. java.lang.IllegalArgumentException

我正在尝试使用JPA将枚举保存并查询到Google App Engine数据存储中。
根据枚举,默认情况下是JPA持久数据类型。但我得到的是以下例外:

com.xxx.utils.ActionLogUtils logCreateUserAction: actiontype: **com.xxx.endpoints.ActionLog$ACTION_TYPE** is not a supported property type.
java.lang.IllegalArgumentException: actiontype: **com.xxx.endpoints.ActionLog$ACTION_TYPE** is not a supported property type.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:235)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:207)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:173)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:148)
    at com.google.appengine.api.datastore.PropertyContainer.setProperty(PropertyContainer.java:101)
我的实体类如下所示:

@Entity
public class ActionLog {

public static enum ACTION_TYPE {
    ACTION_1(1),
    ACTION_2(2),
    ACTION_3(3);

    private final int value;
    private ACTION_TYPE(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}


private ACTION_TYPE actiontype;

public ActionLog() {

}

public ACTION_TYPE getActiontype() {
    return actiontype;
}

public void setActiontype(ACTION_TYPE actiontype) {
    this.actiontype = actiontype;
}
}
导致异常的代码是:

public static void logCreateUserAction(String userId) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    try {
        Key userKey = KeyFactory.createKey("User", userId);
        Entity actionLogEntity = new Entity("ActionLog", userKey);  
        actionLogEntity.setProperty("actiontype", ACTION_TYPE.ACTION_1);
        datastore.put(actionLogEntity);
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
}
我做错了什么?我真的搜索了网络和谷歌的文档,但找不到任何关于枚举的信息。你能帮忙吗?我在这里真的累坏了


非常感谢。我真的很感激。

有一个公共测试显示在JPA和GAE中使用枚举,一切正常。建议你调试你的代码,看看你做了什么不同@谢谢你的回复。有没有一种方法可以使用低级API持久化枚举(或者模拟JPA的方式)?我上面写的方法也可以从servlets调用,在那里我没有访问EntityManager实例的权限。你不会说你正在使用哪个版本的Google JPA插件,也不会说你为什么要引用DataNucleus文档的v2.2,我不知道(Google插件的任何版本都不能使用)。您省略了堆栈跟踪的其余部分,该跟踪将提供有关其来源的有用信息。再看看log@DataNucleusIm使用JPA插件v2。堆栈跟踪的其余部分与问题无关,因为它描述了我的应用程序代码。我给我忘记放在上面的方法添加了两行,希望能澄清一些事情(Entity扩展了PropertyContainer,这是堆栈跟踪中的最后一行)。从您的声音中,我了解到这是一个假设使用枚举的常见操作?通过低级API持久化枚举属性?@DataNucleus是否愿意分享您的想法?