AppEngine JDO查询未按预期工作

时间:2013-05-12 14:59:35

标签: java google-app-engine jdo

我正在使用AppEngine,我想用以下方式查询数据实体:

  • Bool数据'可选'为False。
  • 日期'registrationTimestamp'的升序。

我的代码:

Query query = pm.newQuery(DeviceInfo.class);
query.setFilter("optional == False");
query.setOrdering("registrationTimestamp asc");
List<DeviceInfo> datas = (List<DeviceInfo>)query.execute();

当我看到数据时,有'可选'的数据为True。我想过滤掉'op​​tional'为True的条目。似乎setFilter(“optional == False”)无效。

如何执行我想要的查询?

修改

我使用了DataBucleus建议的DEBUG级别的日志。

org.datanucleus.plugin.NonManagedPluginRegistry resolveConstraints: Bundle "org.datanucleus.jpa" has an optional dependency to "org.datanucleus.enhancer" but it cannot be resolved
org.datanucleus.plugin.NonManagedPluginRegistry resolveConstraints: Bundle "org.datanucleus" has an optional dependency to "org.eclipse.equinox.registry" but it cannot be resolved
org.datanucleus.plugin.NonManagedPluginRegistry resolveConstraints: Bundle "org.datanucleus" has an optional dependency to "org.eclipse.core.runtime" but it cannot be resolved
org.datanucleus.PersistenceConfiguration setProperty: Property datanucleus.rdbms.sql.allowAllSQLStatements unknown - will be ignored
org.datanucleus.PersistenceConfiguration setProperty: Property datanucleus.rdbms.stringDefaultLength unknown - will be ignored
org.datanucleus.PersistenceConfiguration setProperty: Property datanucleus.appengine.autoCreateDatastoreTxns unknown - will be ignored
org.datanucleus.ObjectManagerFactoryImpl logConfiguration: ================= Persistence Configuration ===============
org.datanucleus.ObjectManagerFactoryImpl logConfiguration: DataNucleus Persistence Factory - Vendor: "DataNucleus"  Version: "1.1.5"
org.datanucleus.ObjectManagerFactoryImpl logConfiguration: DataNucleus Persistence Factory initialised for datastore URL="appengine" driver="" userName=""
org.datanucleus.ObjectManagerFactoryImpl logConfiguration: ===========================================================
org.datanucleus.PersistenceConfiguration setProperty: Property datanucleus.query.cached unknown - will be ignored
org.datanucleus.jdo.metadata.JDOMetaDataManager <init>: Registering listener for metadata initialisation
org.datanucleus.jdo.metadata.JDOAnnotationReader processClassAnnotations: Class "net.xxxxxxxxx.xxxxxxx.server.DeviceInfo" has been specified with JDO annotations so using those.
org.datanucleus.store.appengine.MetaDataValidator validate: Performing appengine-specific metadata validation for net.xxxxxxxxx.xxxxxx.server.DeviceInfo
org.datanucleus.store.appengine.MetaDataValidator validate: Finished performing appengine-specific metadata validation for net.xxxxxxxxx.xxxxxx.server.DeviceInfo
org.datanucleus.store.StoreDataManager registerStoreData: Managing Persistence of Class : net.xxxxxxxxx.xxxxxxx.server.DeviceInfo [Table : <class name="DeviceInfo"
       identity-type="application"
       objectid-class="javax.jdo.identity.ObjectIdentity"
       persistence-modifier="persistence-capable"
>
<inheritance strategy="new-table">
</inheritance>
<field name="deviceRegistrationID"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="gcm"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="key"
       persistence-modifier="persistent"
       primary-key="true"
       null-value="none"
       default-fetch-group="true"
       embedded="false"
       unique="false">
</field>
<field name="optional"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="registrationTimestamp"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
</class>
, InheritanceStrategy : new-table]
org.datanucleus.store.StoreDataManager registerStoreData: Managing Persistence of Class : net.xxxxxxxxx.xxxxxxx.server.DeviceInfo [Table : <class name="DeviceInfo"
       identity-type="application"
       objectid-class="javax.jdo.identity.ObjectIdentity"
       persistence-modifier="persistence-capable"
>
<inheritance strategy="new-table">
</inheritance>
<field name="deviceRegistrationID"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="gcm"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="key"
       persistence-modifier="persistent"
       primary-key="true"
       null-value="none"
       default-fetch-group="true"
       embedded="false"
       unique="false">
</field>
<field name="optional"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
<field name="registrationTimestamp"
       persistence-modifier="persistent"
       null-value="none"
       default-fetch-group="true"
       embedded="true"
       unique="false">
</field>
</class>
, InheritanceStrategy : new-table]
org.datanucleus.jdo.metadata.JDOMetaDataManager$MetaDataRegisterClassListener registerClass: Listener found initialisation for persistable class net.xxxxxxxxx.xxxxxxx.server.DeviceInfo
com.google.appengine.api.datastore.QueryResultsSourceImpl logChunkSizeWarning: This query does not have a chunk size set in FetchOptions and has returned over 1000 results.  If result sets of this size are common for this query, consider setting a chunk size to improve performance.
  To disable this warning set the following system property in appengine-web.xml (the value of the property doesn't matter): 'appengine.datastore.disableChunkSizeWarning'

1 个答案:

答案 0 :(得分:0)

虽然直接黑客

optional = false 

应该有效,您应该考虑根据documentation

正确添加过滤器
Query q = new Query("DeviceInfo")
            .addFilter("optional",
                       Query.FilterOperator.EQUAL,
                       false);

希望有所帮助