-
Notifications
You must be signed in to change notification settings - Fork 455
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
EnsureIndexes() fails when my Entity contains Embedded List<HashMap<K, V>> #923
Comments
can you post your entity source? |
The indexes annotations are @Indexes({
@Index(fields = @Field(value = "resourceType", type = IndexType.ASC), options = @IndexOptions()),
@Index(fields = @Field(value = "administrative.withCreator", type = IndexType.ASC), options = @IndexOptions()),\
@Index(fields = @Field(value = "administrative.externalId", type = IndexType.ASC), options = @IndexOptions()),
@Index(fields = @Field(value = "provenance.provider", type = IndexType.ASC), options = @IndexOptions()),
@Index(fields = @Field(value = "provenance.resourceId", type = IndexType.ASC), options = @IndexOptions()),
@Index(fields = @Field(value = "descriptiveData.label", type = IndexType.ASC), options = @IndexOptions()),
@Index(fields = @Field(value = "collectedIn", type = IndexType.ASC), options = @IndexOptions()) }) and the field which creates the problem is @Embedded
private List<HashMap<MediaVersion, EmbeddedMediaObject>> media; Because the full entity was to big I pasted it on that link [http://pastebin.com/KNUa1VcR] thanks again, |
Great, thanks. I'll try to play with this today and see what shakes out. |
I had to massage the code a little to get things to compile/resolve properly (because I don't have your entire model which is fine-ish) and i get a different error. "Generic TypeVariable not supported" which is more in keeping with what I expected to see since Morphia has issues mapping unbound type parameters. I don't suppose you can put together a complete test case and zip it up somewhere? |
Sorry for being late :-P Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class |
Looking in to this, I see where the problem is and even have a good grasp on what the fix is. Sadly, it duplicates a lot of the work targeted for 2.0(ish) which includes a rewrite of the mapping code. I'm not quite ready, yet, to say "just wait for 2.0" because that's not a great answer but I'm mulling my options here. I'd rather not go through the work of (re)fixing this code only to throw it away in a (hopefully) few months. |
I totally agree @evanchooly . Otherway or not we have managed to overcome this problem by indexing the field we want manually. PS: Could you give me a hint about the bug or the code in order to try to understand how the mapping system of Morphia works? |
It has to do with how morphia is discovering and tracking generic types. The code is rather gnarly which is why it's being replaced. MappedField and EphemeralMappedField (terrible name even though I chose it) are the guts of where the failure lies. |
For me that is fine. The described workaround from #921 is just a few lines long and therefore does not hurt. I'm happy to remove it when 2.0 arrives. ;-) |
This appears to work on 2.0. I'm going to revive the 2.0.0-SNAPSHOT publishing (it normally happens automatically with every commit but some quality checks are fading.) If you feel up for testing it against 2.0 (even in a test project), I'd love the feedback. |
snapshot builds are pushing again and should be regularly updated after each build should you want to give them a try. |
Hello,
I have a class (ket's say MyClass.java) annotated with @Entity with has a field of type List<HashMap<K, V>> field_1 annotated with @Embedded.
I can store documents in a proper way as list of DBObjects eg:
[{ .... }, { ... }, {},... ]
but when I'm running Datastore's method
ensureIndexes(MyClass.class) I get the following exception,
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class at org.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:199) ~[morphia-1.0.1.jar:na] at org.mongodb.morphia.mapping.MappedField.discover(MappedField.java:117) ~[morphia-1.0.1.jar:na] at org.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:95) ~[morphia-1.0.1.jar:na] at org.mongodb.morphia.mapping.MappedClass.discover(MappedClass.java:214) ~[morphia-1.0.1.jar:na] at org.mongodb.morphia.mapping.MappedClass.<init>(MappedClass.java:145) ~[morphia-1.0.1.jar:na]
As you can understand I use morphia version 1.0.1.
I have tried with 1.1.1 having the same exception, and with 0.111 I couldn't compile my code!
The text was updated successfully, but these errors were encountered: