views:

311

answers:

1

so I am trying to build a google app engine using servlets, filters etc. I have a java file that looks something like:

public class Idea implements Comparator<Idea> {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Persistent
private User author;

@Persistent
private String content;

@Persistent
private Date date;

@Persistent
private Map<User, Boolean> positiveVotes ;

@Persistent
private Map<User, Boolean> negativeVotes;

public Idea(User author, String content, Date date) {
    this.author = author;
    this.content = content;
    this.date = date;
    this.positiveVotes = new HashMap<User, Boolean>();
    this.negativeVotes = new HashMap<User, Boolean>();
}

but when I try to run my program, I get an exception stack beginning with:

Feb 13, 2010 5:01:23 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: /sign
java.lang.IllegalArgumentException: positiveVotes: java.util.HashMap is not a supported property type.
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:145)
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:127)
at com.google.appengine.api.datastore.Entity.setProperty(Entity.java:280)

So, my question is why does it complain that java.util.HashMap is not a supported property type, and also what could I do to work around it. Thanks! hope someone replies soon.

+1  A: 

It's not a supported type for serialization. You can review the list of supported types, and consider alternative designs. I could be missing something, but can you just keep sets of the users who support or oppose the idea? What is the purpose of the boolean? Note that HashSet is a supported type.

Matthew Flaschen
so what can i do if i want to have a map field in my class?
urfriend
Can you show more code, or explain the purpose of the boolean value?
Matthew Flaschen
actually i noticed hashmap is actually serializable http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html.
urfriend
Yes, it implements Serializable, but App Engine does not support persisting it.
Matthew Flaschen
the purpose of boolean is in my jstl code in my jsp file. i m using scriptless jsp and i need boolean to see if a user voted for a particular idea.
urfriend
so u just can't persist a map of any kind in app engine?
urfriend
No, maps can't be persisted. Can you keep sets or lists of the users who voted up and down? That is supported.
Matthew Flaschen
i tried working with lists but i really map apparently. the thing is from jstl, i can't call a method on my idea object by passing in parameter. so the only alternative is to use a map and see if a user has a mapping.
urfriend