asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Polymorphic @Mapify does not work (Objectify 5) #196

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Mapify annotation does not work on polymorphic embedded classes.
I don't think it is a configuration problem because if I use a list it works.

I attached a JUnit test to reproduce the problem.

com.googlecode.objectify.SaveException: Error saving 
com.googlecode.objectify.PolymorphicMapifyTest$ContainerWithSuperClassMapify@5ef
faa35: Class 'class com.googlecode.objectify.PolymorphicMapifyTest$SubClass' is 
not a registered @Subclass
    at com.googlecode.objectify.impl.EntityMetadata.save(EntityMetadata.java:95)
    at com.googlecode.objectify.impl.WriteEngine.save(WriteEngine.java:74)
    at com.googlecode.objectify.impl.SaverImpl.entities(SaverImpl.java:60)
    at com.googlecode.objectify.impl.SaverImpl.entity(SaverImpl.java:35)
    at com.googlecode.objectify.PolymorphicMapifyTest.testPoliformicEmbeddedMapify(PolymorphicMapifyTest.java:76)
...
Caused by: java.lang.IllegalStateException: Class 'class 
com.googlecode.objectify.PolymorphicMapifyTest$SubClass' is not a registered 
@Subclass
    at com.googlecode.objectify.impl.translate.ClassTranslator.saveSafe(ClassTranslator.java:131)
    at com.googlecode.objectify.impl.translate.ClassTranslator.saveSafe(ClassTranslator.java:21)
    at com.googlecode.objectify.impl.translate.NullSafeTranslator.save(NullSafeTranslator.java:25)
    at com.googlecode.objectify.impl.translate.MapifyTranslatorFactory$1.save(MapifyTranslatorFactory.java:81)
    at com.googlecode.objectify.impl.translate.MapifyTranslatorFactory$1.save(MapifyTranslatorFactory.java:43)
    at com.googlecode.objectify.impl.PropertyPopulator.save(PropertyPopulator.java:135)
    at com.googlecode.objectify.impl.translate.ClassPopulator.save(ClassPopulator.java:149)
    at com.googlecode.objectify.impl.translate.ClassTranslator.saveSafe(ClassTranslator.java:138)
    at com.googlecode.objectify.impl.translate.ClassTranslator.saveSafe(ClassTranslator.java:21)
    at com.googlecode.objectify.impl.translate.NullSafeTranslator.save(NullSafeTranslator.java:25)
    at com.googlecode.objectify.impl.EntityMetadata.save(EntityMetadata.java:89)
    ... 28 more

I use the 5.0 version.

Original issue reported on code.google.com by tamas.to...@doctusoft.com on 19 Apr 2014 at 9:55

Attachments:

GoogleCodeExporter commented 9 years ago
Currently when you register a subclass you register it with an annotationless 
TypeKey.
If you try to use this subclass in place of an annotated superclass (@Mapify, 
@Stringify, @Unindex, @Index) you get an exception.

Pull request with the fix:
https://github.com/stickfigure/objectify/pull/12

Original comment by tamas.to...@doctusoft.com on 20 Apr 2014 at 11:29

GoogleCodeExporter commented 9 years ago
Thank you for the PR and the great tests. I believe I can come up with a 
somewhat more elegant solution, but I am very impressed that you solved it!

Original comment by lhori...@gmail.com on 20 Apr 2014 at 4:36

GoogleCodeExporter commented 9 years ago
This was solved by caching the class translators in the factory. Thank you for 
finding this!

Fixed in 5.0.1

Original comment by lhori...@gmail.com on 20 Apr 2014 at 5:01