Open GoogleCodeExporter opened 9 years ago
I have the exact opposite situation where the classname is recorded and (I
think) shouldn't be. I'm guessing this is most likely related so I've attached
my test case to this issue rather than creating another. If another issue needs
to be created, I'll gladly do so.
In my case, if I save the entire document, the classname is not recorded as I
expect. If instead, I update (set) the field, the classname is recorded.
Mongo/Driver/Morphia: 1.8.2/2.6.5/0.99 (also built from trunk)
public class MapTest {
@Entity(value="foo", noClassnameStored=true)
public static class Foo {
@Id
private ObjectId id;
@Embedded("bars")
private Map<String, Bar> bars = new HashMap<String, Bar>();
}
@Embedded
public static class Bar {
@Property("a-value")
private String a;
@Property("b-value")
private String b;
}
public static final void main( String [] args ) throws Throwable {
Mongo mongo = new Mongo( "localhost" );
Morphia morphia = new Morphia();
morphia.map( Foo.class );
Datastore datastore = morphia.createDatastore( mongo, "test" );
Foo foo = new Foo();
Bar bar = new Bar();
bar.a = "AAAA";
bar.b = "BBBB";
foo.bars.put( "1", bar );
datastore.save( foo ); // works as expected
foo = new Foo();
datastore.save( foo );
bar = new Bar();
bar.a = "aaaa";
bar.b = "bbbb";
foo.bars.put( "2", bar );
// records classname
datastore.update( foo, datastore.createUpdateOperations( Foo.class ).set( "bars", foo.bars ) );
}
}
> db.foo.find()
{ "_id" : ObjectId("4ea8ce481a8885d6d212efa0"), "bars" : { "1" : { "a-value" :
"AAAA", "b-value" : "BBBB" } } }
{ "_id" : ObjectId("4ea8ce491a8885d6d212efa1"), "bars" : { "2" : { "className"
: "test.mongo.morphia.MapTest$Bar", "a-value" : "aaaa", "b-value" : "bbbb" } } }
Original comment by randy.n...@gmail.com
on 27 Oct 2011 at 6:10
We're seeing the same issue to comment 1, with a classname being added to an
embedded map field even though the parent entity has noClassnameStored=true.
One workaround is to add @Entity(noClassnameStored=true) on the embedded class
(as well as @Embedded)
Original comment by one...@energyhub.net
on 31 Jul 2012 at 8:36
Original issue reported on code.google.com by
j...@yottaa.com
on 1 Jul 2011 at 2:14