Skip to content

Inconsistent type alias placement in list of classes [DATAMONGO-1509] #2420

Closed
@spring-projects-issues

Description

@spring-projects-issues

Tomasz Grabarczyk opened DATAMONGO-1509 and commented

I have the following classes:

@Document
public class TestDocument {
	
	@Id private String id;
	private List<TestClass> testClassList;

	public TestDocument() {
		this.testClassList = null;
	}
	
	public TestDocument(List<TestClass> testClassList) {
		this.testClassList = testClassList;
	}
}
public class TestClass { }
public class TestSubClass extends TestClass {

	private String field;

	public TestSubClass(String field) {
		this.field = field;
	}
}

Now I run the following code:

TestClass testClass = new TestSubClass("value");
mongoTemplate.insert(new TestDocument(Arrays.asList(testClass)));
Query query = Query.query(Criteria.where("testClassList").is(testClass));
TestDocument result = mongoTemplate.findOne(query, TestDocument.class);
System.out.println(result);		// prints: null

I would expect that this query should return the document I inserted at the beginning, but it doesn't. The reason for that is that the TestClass is converted differently when saving document, and differently when creating the query:

Document saved to the database:

"_id" : ObjectId("57fe47fd24474e28ec1db2ed"),
"_class" : "TestDocument",
"testClassList" : [
    {
        "field" : "value",
        "_class" : "TestSubClass"
    }
]

The query:

{ "testClassList" : { "_class" : "TestSubClass" , "field" : "value"}}

I think it shouldn't be like that


Affects: 1.10 M1 (Ingalls), 1.9.4 (Hopper SR4)

Issue Links:

  • DATAMONGO-1210 Inconsistent property order of _class type hint breaks document equality

Referenced from: pull request #411, and commits e987a85, 987461a, c9573ed, 3c16b4d, 8c50baa, 0ee8789, d6f560d

Metadata

Metadata

Labels

in: mappingMapping and conversion infrastructuretype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions