I have some data stored in MongoDb, that currently I do not want to map on POJO, How we can get all unstructured fields of Documents in a single map.
I found this link
http://www.carfey.com/blog/using-mongodb-with-morphia/
that says you can mapped all unstructured fields using
// .. our base attributes here
private Map<String, Object> attributes
but its not working as I am contiguously getting it null, I checked the Morphia code, It iterates on Morphia entity class fields, so how can we get all DBObject unmapped fields in attributes Map.
Out of interest: Why would you do that? You'll need to map the class and the one field, in which you want to add your data, to Morphia anyway. Or am I misunderstanding you?
How to do it: You'll need to annotate all fields you want to store in the map with @Transient
and add / load them in your custom @PrePersist
and @PostLoad
methods.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.