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.
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)
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);
}
}