Google App Engine datastore - Enums

8 views
Skip to first unread message

AsafK via StackOverflow

unread,
Nov 19, 2013, 8:29:53 PM11/19/13
to google-appengin...@googlegroups.com

Im trying to save and query an enum into a Google App Engine datastore using JPA.
According to DataNucleas an Enum is a JPA persistable data type by default. But what im getting is the following exception :

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)

my entity class looks like this :

@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;
}
}

And the code that causes the exception is :

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

    try {
        actionLogEntity.setProperty("actiontype", ACTION_TYPE.ACTION_1);
        datastore.put(actionLogEntity);
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
}

What am i doing wrong here ? I really searched the web and google's documenation but couldn't find anything about enums. Can you please help ? Im really stucked here.

Thanks a lot. I really appreciate it.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/20085624/google-app-engine-datastore-enums

AsafK via StackOverflow

unread,
Nov 20, 2013, 1:05:00 AM11/20/13
to google-appengin...@googlegroups.com

Im trying to save and query an enum into a Google App Engine datastore using JPA.
According to DataNucleas an Enum is a JPA persistable data type by default. But what im getting is the following exception :

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)

AsafK via StackOverflow

unread,
Nov 20, 2013, 5:11:51 PM11/20/13
to google-appengin...@googlegroups.com
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);
    }
}
Reply all
Reply to author
Forward
0 new messages