java - Morphia List<Map<String,Object>>> return Embedded element isn't a DBObject on find operation -


I have tried to do something like this:

  package org.dnylabs.kosh. Information; Import java.net.UnknownHostException; Import java.util.HashMap; Import java.util.LinkedList; Import java.util.list; Import java.util.Map; Import Com.google.code.morphia.Datastore; Import Com.google.code.morphia.Morphia; Import Com.google.code.morphia.annotations.Entity; Import Com.google.code.morphia.annotations.Id; Import com.mongodb.mongo; Import com.mongodb.MongoException; @Entity Public Class Temp {@ Id String _id; & Lt; Maps & LT; String, Object & gt; & Gt; Wire; Public Temporary () {string = new linked list & lt; Maps & lt; String, Object & gt; & Gt; (); } Public static zero main (string [] args) unknownhost explodes, throws MongoException {Mongo mongo = null; Morphia morphia = null; Datastore ds = null; Mongo = new mongo (); Morphia = new morphia (); Morphia.map (temp.class); Ds = morphia.createDatastore (mongo, "test"); Temporary t = new temporary (); T._id = "hi"; Maps & lt; String, Object & gt; M = new hashmop & lt; String, Object & gt; (); M.put ("hi", "1"); M.put ("Hi2", 2); T.strings.add (m); Ds.save (t); T = ds.get (t); Ds.ensureIndexes (); }}  

When I try to do the findAll (9 operation) I get an exception:

   

After several attempts I have found that the problem is the carved map.

Can anyone understand why I am wrong? The statement seems right.

Instead of viewing mafia as an embedded class and behaving as a document, DB sees the map as a reference in the other document. Its solution must be commented on the map @ embedded, but this is not possible because you can not edit the map class.

Whatever you are trying to create in another class, and define the map as the property of this class and it is annotated as an @ ambedday.

Change the Temporary Class:

  Public Class Temp {@Id String _id; @ Embedded // change list here & lt; MapProxy & gt; Wire; // here public temp () {strings = new linked list & lt; MapProxy & gt; (); // change here} public static zero main (string ... args) unknownhost throws, MongoException {Mongo Mongo = tap; Morphia morphia = null; Datastore ds = null; Mongo = new mongo (); Morphia = new morphia (); Morphia.map (temp.class); Ds = morphia.createDatastore (mongo, "test2"); Temporary t = new temporary (); T._id = "hi"; MapProxy MP = new MapProxy (); // change here mp.m.put ("hi", "1"); // change here mp.m.put ("Hi2", 2); // Change T.strings.add (MP3) here; // Change ds.save (t) here; T = ds.get (t); Ds.ensureIndexes (); }}  

and create a new class:

  @ Embedded public class MapProxy {public map & lt; String, Object & gt; M = new hashmop & lt; String, Object & gt; (); }  

I marked the changes I made.

This is the structure that is:

  {"_id": "hi", "classname": "your class name is here", "strings ": [{" M ": {" hi ":" 1 "," hi 2 ": 2}}}}  

Comments