Java 按id对象化加载@子类

Java 按id对象化加载@子类,java,google-app-engine,objectify,Java,Google App Engine,Objectify,我有这些课程: @Entity(name = "Post") public abstract class PostRecord { @Id private Long id; } @Subclass(name = "Bulletin", index = true) public class BulletinRecord extends PostRecord { } 我正试图通过id获取bulletinRecord,但我总是得到null。 以下是我的尝试: ofy().lo

我有这些课程:

@Entity(name = "Post")
public abstract class PostRecord {

    @Id
    private Long id;
}


@Subclass(name = "Bulletin", index = true)
public class BulletinRecord extends PostRecord {

}
我正试图通过id获取bulletinRecord,但我总是得到null。 以下是我的尝试:

ofy().load().type(BulletinRecord.class).id(bulletinId).now();
ofy().load().type(PostRecord.class).id(bulletinId).now();
ofy().load().key(Key.create(Key.create(PostRecord.class , bulletinId), BulletinRecord.class, bulletinId)).now();
ofy().load().type(BulletinRecord.class).filter("id=", postId).first().now();
ofy().load().type(PostRecord.class).filter("id=", postId).first().now();
我可以在开发人员控制台上看到我的记录,其中的id是我试图获取的:


有人能告诉我我做错了什么吗?谢谢。

问题出在哪里还不清楚。如果您的类与您描述的完全相同,那么前两行应该可以使用。第三行行不通,因为您试图使用
@Parent
键。最后两个不起作用,因为您不能按
@Id
字段进行筛选(它们不是索引属性,它们是键的一部分)。很抱歉,来晚了。我有其他没有子类的实体,我可以通过id获取它们,第一行和第二行如何。我唯一无法通过id获得的情况是使用子类。这些实体PostRecord有3个子类:BulletinRecord、SessionRecord和NewsRecord。我可以列出所有公告、所有会议、所有新闻或所有帖子。当我尝试列出时,它工作得很好,但当我尝试按id获取时,我得到null。我已经检查了id,它是正确的id。感谢@stickfigure,我解决了我的问题。post record类有其他字段,我不把它们放在这里,因为我认为它们对我的问题不重要。我错了。这篇文章有一个@Parent字段,在看到你的评论后,我尝试了以下代码:key.create(key.create(key.create(UserRecord.class,userId),BulletinRecord.class,bulletinId)).now()并且它工作得非常好。