Hi,
I'm trying to serialize an entity field which is a HashMap of which
the key is a URL string
ex :
@Entity("ffobar")
public class MyEntityFoo {
Map<String, Integer> myField = new HashMap<String,Integer>();
public void dostuff(){
myField.put("
http://groups.google.com/group/morphia/post", 123);
}
}
The problem I get when saving the entity if mongodb throws an
exception because of the dots
"." contained in the URL string map key.
the error is :
java.lang.IllegalArgumentException: fields stored in the db can't
have . in them. (Bad Key: '
http://groups.google.com/group/morphia/
post')
at com.mongodb.DBCollection.validateKey(DBCollection.java:1213)
at com.mongodb.DBCollection._checkKeys(DBCollection.java:1196)
at com.mongodb.DBCollection._checkKeys(DBCollection.java:1186)
at com.mongodb.DBCollection._checkObject(DBCollection.java:1171)
at com.mongodb.DBCollection.save(DBCollection.java:718)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:772)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:834)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:828)
at com.google.code.morphia.dao.BasicDAO.save(BasicDAO.java:109)
What can I do ? Any way around this ?
I figured this accidentally but I think that I now need to check
everywhere I use Map with a String key to store data because this can
happen anywhere you use a String ...
Thanks for your feedback !
Alex