App Engine Objectify 未在基础 class 字段上创建索引
App Engine Objectify not creating index on base class field
假设我有一个简单的实体层次结构设置,其中基础(抽象)class 具有公共字段:
@Entity
public abstract class Base {
@Id
Long mId;
@Index
Long mVal;
}
现在我有一个子class(在Java和Objectify中):
@Subclass(index=true)
public class Concrete extends Base {
@Index mOtherVal;
}
保存 Concrete
时,它会在数据存储中正确地为所有字段(mId
、mVal
和 mOtherVal
)创建条目。但是,如果我尝试 运行 对 Concrete
条目进行查询并在 mVal
上使用过滤器,应用引擎会抱怨没有索引:
List<Concrete> result =
OfyService.ofy().load().type(Concrete.class).filter("mVal > ", 10).list();
我看到这样的异常日志:
com.google.api.server.spi.SystemService invokeServiceMethod: cause={0}
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="^i" direction="asc"/>
<property name="mVal" direction="asc"/>
</datastore-index>
我没有故意创建 datastore-indexes.xml
,因为 Objectify 文档声明字段索引是动态创建的。所以我的问题是:这是 Objectify 的已知限制,还是我做错了什么?
您可能已经从问题的评论中了解到,您需要 datastore-indexes.xml
中的多 属性 索引。
我希望这很明显为什么这是必要的——你正在请求一个查询,其中 mVal
受到不等式和鉴别器索引的约束(由 Objectify 作为 属性 ^i
) 包括特定值。如果你想更聪明一点,你可以查询 ofy().load().type(Base.class).filter("mVal > ", 10)
并且你不需要额外的索引,因为简单的单个 属性 索引就足够了。
Multi属性 索引(由 GAE 在 datastore-indexes.xml 中维护)与 Objectify 维护的单个 属性 索引非常不同。这在 GAE 文档中有详细解释。
假设我有一个简单的实体层次结构设置,其中基础(抽象)class 具有公共字段:
@Entity
public abstract class Base {
@Id
Long mId;
@Index
Long mVal;
}
现在我有一个子class(在Java和Objectify中):
@Subclass(index=true)
public class Concrete extends Base {
@Index mOtherVal;
}
保存 Concrete
时,它会在数据存储中正确地为所有字段(mId
、mVal
和 mOtherVal
)创建条目。但是,如果我尝试 运行 对 Concrete
条目进行查询并在 mVal
上使用过滤器,应用引擎会抱怨没有索引:
List<Concrete> result =
OfyService.ofy().load().type(Concrete.class).filter("mVal > ", 10).list();
我看到这样的异常日志:
com.google.api.server.spi.SystemService invokeServiceMethod: cause={0}
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="^i" direction="asc"/>
<property name="mVal" direction="asc"/>
</datastore-index>
我没有故意创建 datastore-indexes.xml
,因为 Objectify 文档声明字段索引是动态创建的。所以我的问题是:这是 Objectify 的已知限制,还是我做错了什么?
您可能已经从问题的评论中了解到,您需要 datastore-indexes.xml
中的多 属性 索引。
我希望这很明显为什么这是必要的——你正在请求一个查询,其中 mVal
受到不等式和鉴别器索引的约束(由 Objectify 作为 属性 ^i
) 包括特定值。如果你想更聪明一点,你可以查询 ofy().load().type(Base.class).filter("mVal > ", 10)
并且你不需要额外的索引,因为简单的单个 属性 索引就足够了。
Multi属性 索引(由 GAE 在 datastore-indexes.xml 中维护)与 Objectify 维护的单个 属性 索引非常不同。这在 GAE 文档中有详细解释。