English 中文(简体)
我如何利用吗?
原标题:How do I store HashMaps in mongodb using morphia?

如何利用吗?

我不敢肯定,这是否是吗.的丑恶,或者如果说是错的话。

1. 说有本领域模式

@Entity("person")
public class Person {
    private String property1;
    private String property2;
    private HashMap<String, Thing> things;
}

i) 如果试图通过扩大基本食品食品食品券的班子来挽救这一错误:(如上所述,UsedView相当于Thing)

java.lang.IllegalArgumentException: can t serialize class com.model.designed.UsedView at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:205) at org.bson.BSONEncoder.putMap(BSONEncoder.java:245) at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:177) at org.bson.BSONEncoder.putObject(BSONEncoder.java:121) at org.bson.BSONEncoder.putObject(BSONEncoder.java:67) at com.mongodb.OutMessage.putObject(OutMessage.java:189) at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:245) at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:209) at com.mongodb.DBCollection.insert(DBCollection.java:66) at com.mongodb.DBCollection.save(DBCollection.java:622) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:731) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:793) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:787) at com.google.code.morphia.dao.BasicDAO.save(BasicDAO.java:109)...

然后,一经修改:

"private HashMap<String, Thing> things"

纽约总部

"private HashMap<String, String> things"

它可免予罚款。

任何想法?

非常感谢!

问题回答

我认识到的老问题,但我来到这里:(未经测试)

...... 这可以包含由MongoDB驾驶员支持的任何基本类型,包括名单和地图,但除非你在Morphia注册转换器(例如:吗?” MyCustomTypeConverter()

From: http://www.carfey.com/blog/using-mongodb-with-morphia/

如前所述:未经测试。

hth.

是否将<条码>三条描绘成一个心脏的实体? 否则,吗? 吗?





相关问题
Something like HashMap but sorted?

I m writing a Java program that parses all the words from a text file and then adds them to a HashMap. I need to count how many distinct words are contained in the file. I also need to figure out the ...

get string value from HashMap depending on key name

I have a HashMap with various keys and values, how can I get one value out? I have a key in the map called my_code, it should contain a string, how can I just get that without having to iterate ...

Is there a Java equivalent of Python s defaultdict?

In Python, the defaultdict class provides a convenient way to create a mapping from key -> [list of values], in the following example, from collections import defaultdict d = defaultdict(list) d[1]....

Internal implementation of java.util.HashMap and HashSet

I have been trying to understand the internal implementation of java.util.HashMap and java.util.HashSet. Following are the doubts popping in my mind for a while: Whats is the importance of the @...

Java HashMap performance optimization / alternative

I want to create a large HashMap but the put() performance is not good enough. Any ideas? Other data structure suggestions are welcome but I need the lookup feature of a Java Map: map.get(key) In ...

Is HashMap in Java collision safe

I am developing a parser that needs to put key value pairs in hashmap. A key can have multiple values which I can do in this way HashMap<String,ArrayList<String>> . What happens if the ...

C++ STL unordered_map problems and doubts

after some years in Java and C# now I m back to C++. Of course my programming style is influenced by those languages and I tend to feel the need of a special component that I used massively: the HASH ...

热门标签