FAQ
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

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupmorphia @
categoriesmongodb
postedMar 6, '12 at 2:06p
activeMar 6, '12 at 2:17p
posts2
users2
websitecode.google.com...
irc#mongodb

2 users in discussion

Azlists: 1 post Ahmet Alp Balkan: 1 post

People

Translate

site design / logo © 2021 Grokbase