Java 带有Objectify 5的多态性
我有以下课程:Java 带有Objectify 5的多态性,java,google-app-engine,objectify,Java,Google App Engine,Objectify,我有以下课程: @Entity(name = "Post") public abstract class PostRecord { @Id private Long id; private String field1; } @Subclass(name = "Bulletin") public class BulletinRecord extends PostRecord { private String field2; } @Subclass(name
@Entity(name = "Post")
public abstract class PostRecord {
@Id
private Long id;
private String field1;
}
@Subclass(name = "Bulletin")
public class BulletinRecord extends PostRecord {
private String field2;
}
@Subclass(name = "Session")
public class SessionRecord extends PostRecord {
private String field3;
}
如何获取所有公告或所有会话?
下面的代码可以正常工作,并返回包含所有公告和会话的帖子列表:
ofy().load().type(PostRecord.class).list();
但我只需要公告或会话,当我尝试下面的代码时,我会得到一个空列表:
ofy().load().type(BulletinRecord.class).list();
ofy().load().type(SessionRecord.class).list();
您需要索引子类鉴别器
@Subclass(name = "Bulletin", index = true)
public class BulletinRecord extends PostRecord {
}
GAE中的所有筛选(如子类筛选)都需要索引;指数有成本;Objectify要求您选择此成本。您需要为子类鉴别器编制索引
@Subclass(name = "Bulletin", index = true)
public class BulletinRecord extends PostRecord {
}
GAE中的所有筛选(如子类筛选)都需要索引;指数有成本;Objectify要求您选择此成本。您需要为子类鉴别器编制索引
@Subclass(name = "Bulletin", index = true)
public class BulletinRecord extends PostRecord {
}
GAE中的所有筛选(如子类筛选)都需要索引;指数有成本;Objectify要求您选择此成本。您需要为子类鉴别器编制索引
@Subclass(name = "Bulletin", index = true)
public class BulletinRecord extends PostRecord {
}
GAE中的所有筛选(如子类筛选)都需要索引;指数有成本;Objectify要求您选择此成本