Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdvancedDatastore.ensureIndexes doesn't handle fields subtypes properly with version 1.3.2 #1175

Closed
dinosavings opened this issue Jun 13, 2017 · 2 comments
Labels
Milestone

Comments

@dinosavings
Copy link

dinosavings commented Jun 13, 2017

Unit test:

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)

morphia version: 1.3.2
mongo driver version: 3.4.2

This was working fine with morphia version .111.

@darklynx
Copy link
Contributor

darklynx commented Nov 8, 2017

I have absolutely the same issue!

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.

Please fix it.

@jyemin jyemin added the bug label Nov 8, 2017
@evanchooly evanchooly added this to the 1.4.0 milestone Sep 24, 2018
evanchooly pushed a commit that referenced this issue Sep 24, 2018
* 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
@evanchooly evanchooly modified the milestones: 1.4.0, 1.5.0 Oct 16, 2018
@evanchooly
Copy link
Member

Fixed with the PR merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants