qickrooms / objectify-appengine

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

Unable to use interface as root of embedded entity polymorphic hierarchy #216

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Register RootEntity and SomeImpl:
public class Test {
    @Entity
    public static class RootEntity {
        @Id public long id;
        public SomeIfc someIfc;
    }

    public static interface SomeIfc {
    }

    @Subclass
    public static class SomeImpl implements SomeIfc {
        public String field;
    }
}

What is the expected output?
Registration should not fail

What do you see instead?
This error when calling ObjectifyService.register(RootEntity.class):

java.lang.IllegalStateException: At path 'someIfc': Error registering 
com.test.Test$RootEntity
    at com.googlecode.objectify.impl.Path.throwIllegalState(Path.java:107)
    at com.googlecode.objectify.impl.translate.ClassPopulator.<init>(ClassPopulator.java:93)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.createEntityClassTranslator(ClassTranslatorFactory.java:66)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:48)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:36)
    at com.googlecode.objectify.impl.translate.Translators.create(Translators.java:138)
    at com.googlecode.objectify.impl.translate.Translators.get(Translators.java:117)
    at com.googlecode.objectify.impl.translate.Translators.getRoot(Translators.java:129)
    at com.googlecode.objectify.impl.EntityMetadata.<init>(EntityMetadata.java:49)
    at com.googlecode.objectify.impl.Registrar.register(Registrar.java:70)
    at com.googlecode.objectify.ObjectifyFactory.register(ObjectifyFactory.java:185)
    at com.googlecode.objectify.ObjectifyService.register(ObjectifyService.java:59)
    ...
Caused by: java.lang.NullPointerException
    at com.googlecode.objectify.impl.translate.CreateContext.getPopulator(CreateContext.java:38)
    at com.googlecode.objectify.impl.translate.ClassPopulator.<init>(ClassPopulator.java:76)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.createEmbeddedClassTranslator(ClassTranslatorFactory.java:75)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:48)
    at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:36)
    at com.googlecode.objectify.impl.translate.Translators.create(Translators.java:138)
    at com.googlecode.objectify.impl.translate.Translators.get(Translators.java:117)
    at com.googlecode.objectify.impl.translate.CreateContext.getTranslator(CreateContext.java:27)
    at com.googlecode.objectify.impl.translate.ClassPopulator.<init>(ClassPopulator.java:88)
    ... 27 more

What version of the product are you using?
5.0.3

When changing SomeIfc to a class, everything works as expected.

Original issue reported on code.google.com by igal.d...@papercut.com on 28 Jul 2014 at 5:05

GoogleCodeExporter commented 9 years ago
This isn't  reasonable because Java interfaces do not have a linear hierarchy. 
Any class can implement any interface... including multiple entity hierarchies. 
It breaks my brain just thinking about it.

If you can find some other Java ORM system that allows this (and thus has 
tackled some of the crazy consequences), open a discussion on the google group 
and we'll see if some of that kind of behavior could be added to Objectify. 

Original comment by lhori...@gmail.com on 28 Jul 2014 at 7:25