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
public void testBadIndexing() {
datastore.ensureIndexes(B.class);
datastore.ensureIndexes(TestObject.class);
}
@Entity
public static class TestObject {
@Indexed
private Long id;
@Embedded
private A a;
}
public static class A {
@Indexed
private Long id;
}
@Entity
public static class B extends A {
@Indexed
private String url;
}
Running testBadIndexing() generates the following exception
org.mongodb.morphia.mapping.MappingException: The path 'a.url' can not be validated against 'MyUnitTest$TestObject' and may represent an invalid index
at org.mongodb.morphia.IndexHelper.calculateKeys(IndexHelper.java:264)
at org.mongodb.morphia.IndexHelper.createIndex(IndexHelper.java:374)
at org.mongodb.morphia.IndexHelper.createIndex(IndexHelper.java:366)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:959)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:954)
While debugging through the implementation I have found that IndexHelper collects indexes from sub-classes (derivated / extended classes) that may contain new fields whereas it should have collected the indexes from parent (super-classes).
That is why index validation logic yields about incorrect index.
* added integration tests to confirm the issue #1175
* collect indexes from subclasses only if field is an interface or abstract class
* fixed errors reported by checkstyle
VPriesnitz
pushed a commit
to VPriesnitz/morphia
that referenced
this issue
Oct 5, 2018
* added integration tests to confirm the issue MorphiaOrg#1175
* collect indexes from subclasses only if field is an interface or abstract class
* fixed errors reported by checkstyle
Unit test:
public void testBadIndexing() {
datastore.ensureIndexes(B.class);
datastore.ensureIndexes(TestObject.class);
}
Running testBadIndexing() generates the following exception
org.mongodb.morphia.mapping.MappingException: The path 'a.url' can not be validated against 'MyUnitTest$TestObject' and may represent an invalid index
morphia version: 1.3.2
mongo driver version: 3.4.2
This was working fine with morphia version .111.
The text was updated successfully, but these errors were encountered: