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

Missing indexes in associations involving generic types [DATAMONGO-1263] #2183

Closed
spring-projects-issues opened this issue Jul 30, 2015 · 7 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

Agustí Sánchez opened DATAMONGO-1263 and commented

When an association between documents involves generic types, the type information is not correctly inferred at startup time resulting in missing indexes.

Please, see https://github.com/agustisanchez/SpringDataMongoDBBug, for code samples.

Given:

  • class Book with index on "ISBN" attribute
  • super class AbstractProduct with index on "name" attribute
  • class ProductWrapper holding attribute "content" of generic type "T extends AbstractProduct"

When defining a class Catalog with a list of "wrapped" books:

  • List<ProductWrapper<Book>> books2 = new ArrayList<>

The index "name" inherited from AbstractProduct is created (book2.content.name) inside "catalog" , but the index defined on the Book class itself (isbn) is not created as Spring Data Mongo is only inferring type infromation from the ProductWrapper class definition (ProductWrapper <T extends AbstractProduct>).

Spring Data MongoDB should be able to infer type information from the list declaration ( List<ProductWrapper<Book>> ), becoming aware that Catalog contains a list of Books, hence indexes defined on Book should be created.

If the wrapper class is defined as ProductWrapper<T>, then no indexes are created at all on Catalog.books2.content


Affects: 1.6.3 (Evans SR3)

Reference URL: https://github.com/agustisanchez/SpringDataMongoDBBug/

Referenced from: pull request #312

Backported to: 1.7.3 (Fowler SR3)

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Have you tried this with a more recent version of Spring Data MongoDB, Fowler SR2 (1.7.2)? We solved a few bugs in the area of generic in the last couple of releases

@spring-projects-issues
Copy link
Author

Jordi Llach Fernandez commented

Yeah, you mean https://jira.spring.io/browse/DATAMONGO-1202 , although the github sample is configured with 1.6.3.RELEASE I've just tried with the recently released Fowler-SR2 and also fails

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Actually I was thinking of DATACMNS-697 as that was the only one that came to my mind directly. Did you upgrade Spring Data Commons to one of the versions mentioned in that ticket, too? Either way, I'll have a look tomorrow morning

@spring-projects-issues
Copy link
Author

Jordi Llach Fernandez commented

Tested with spring data release train Fowler-SR2 which implies spring-data-commons-1.10.2.RELEASE and spring-data-mongodb-1.7.2.RELEASE

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Christoph Strobl - Would you mind having a look? Seems like we're dropping back from TypeInformation to Class somewhere in the type resolution and thus fall back to the generic bound instead of using the concrete type somewhere

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

There's a glitch in MongoPersistentEntityIndexResolver using MongoPersistentProperty.getActualtype() where we should be using the TypeInformation provided by MongoPersistentProperty.getTypeInformation().getActualType(). Will add tests and fix.
Good catch Jordi Llach Fernandez and thanks for the sample!

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

already on github 82850d for 1.7.x and 9da432 for 1.8.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants