Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hashmap in persistence manager

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.

like image 872
urfriend Avatar asked Feb 13 '10 18:02

urfriend


1 Answers

You can ask GAE to store the HashMap as a Blob value by adding the JDO annotation to flag this field as being stored serialised:

@Persistent(serialized="true")

https://code.google.com/intl/pl/appengine/docs/java/datastore/dataclasses.html#Serializable_Objects

like image 185
Sean Horgan Avatar answered Oct 11 '22 13:10

Sean Horgan