You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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:
Maybe I am missing something here but are you saying the query doesn't match if _class appears beforefield in the query and it's stored the other way around in the document?
thanks for reporting - yes the order of _class seems to get messed up during the conversion. Will need to have a closer look where that actually happens
Tomasz Grabarczyk opened DATAMONGO-1509 and commented
I have the following classes:
Now I run the following code:
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:
The query:
I think it shouldn't be like that
Affects: 1.10 M1 (Ingalls), 1.9.4 (Hopper SR4)
Issue Links:
Referenced from: pull request #411, and commits e987a85, 987461a, c9573ed, 3c16b4d, 8c50baa, 0ee8789, d6f560d
The text was updated successfully, but these errors were encountered: