Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java应用程序引擎数据存储:如何查询对象继承类的字段?_Java_Google App Engine_Jdo_Google Cloud Datastore - Fatal编程技术网

Java应用程序引擎数据存储:如何查询对象继承类的字段?

Java应用程序引擎数据存储:如何查询对象继承类的字段?,java,google-app-engine,jdo,google-cloud-datastore,Java,Google App Engine,Jdo,Google Cloud Datastore,附录1.2.2。我定义了一个类产品,如下所示: @PersistenceCapable(identityType = IdentityType.APPLICATION, table="Products") public class Product { public Product(String title) { super(); this.title = title; } public String getTitle() { return title; } @Pers

附录1.2.2。我定义了一个类产品,如下所示:

@PersistenceCapable(identityType = IdentityType.APPLICATION, table="Products")
public class Product {

 public Product(String title) {
  super();
  this.title = title;
 }

 public String getTitle() {
  return title;
 }

 @Persistent
 String title;

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key id;
}
我定义了一个派生类书,如下所示:

@PersistenceCapable(identityType = IdentityType.APPLICATION, table="Products")
public class Book extends Product {

 public Book(String author, String title) {
  super(title);
  this.author = author;
 }

 public String getAuthor() {
  return author;
 }

 @Persistent
 String author;
}
然后我创建一个新对象,如下所示:

@PersistenceCapable(identityType = IdentityType.APPLICATION, table="Products")
public class Product {

 public Product(String title) {
  super();
  this.title = title;
 }

 public String getTitle() {
  return title;
 }

 @Persistent
 String title;

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key id;
}
PersistenceManager pm=PMF.get.getPersistenceManager; pm.makePersistentnew Book乔治·奥威尔,1984年

我可以使用如下查询来查询此新对象:

Query Query=pm.newQueryselect from+Book.class.getName+其中author==param; query.declareParametersString参数; List results=List query.EXECUTEGORGE Orwell

这将返回对象,因为我正在查询Book上定义的字段“author”

但是,这不起作用:

Query Query=pm.newQueryselect from+Book.class.getName+其中title==param; query.declareParametersString参数; List results=List query.execute1984

它抛出一个异常,声明没有字段“title”,即使它是在派生类产品上定义的

javax.jdo.JDOUserException: Field "title" does not exist in com.example.Book or is not persistent
NestedThrowables:
org.datanucleus.store.exceptions.NoSuchPersistentFieldException: Field "title" does not exist in com.example.Book or is not persistent
似乎继承类中的字段在数据存储查询中不可用


这实际上可能是语法上的变化还是注释?

使用DataNucleus和我们支持的任何其他数据存储(如RDBMS、XML、Excel等)进行查询时,确实应该允许超类中的字段;该查询是有效的JDOQL。如果他们不在GAE/J中工作,那么在谷歌的问题跟踪程序中报告这个问题,尽管那里肯定已经有关于继承的问题了

该查询将DataNucleus与我们支持的任何其他数据存储(如RDBMS、XML、Excel等)一起使用,确实应该允许超类中的字段;该查询是有效的JDOQL。如果他们不在GAE/J中工作,那么在谷歌的问题跟踪程序中报告这个问题,尽管那里肯定已经有关于继承的问题了

来自:

JDO不支持的特性

App Engine实现不支持JDO接口的以下功能:

无主关系。可以使用显式键值实现无主关系。JDO的无主关系语法在未来的版本中可能会得到支持。 拥有多对多关系

加入查询。在对父类执行查询时,不能在筛选器中使用子实体的字段。请注意,您可以在查询中使用键直接测试父级的关系字段

JDOQL分组和其他聚合查询

多态查询。不能通过查询类来获取子类的实例。每个类在数据存储中由一个单独的实体类表示

@PersistenceCapable注释的IdentityType.DATASTORE。仅支持IdentityType.APPLICATION

当前存在一个错误,阻止将超类上的持久字段保存到数据存储中。这将在以后的版本中修复。

来自:

JDO不支持的特性

App Engine实现不支持JDO接口的以下功能:

无主关系。可以使用显式键值实现无主关系。JDO的无主关系语法在未来的版本中可能会得到支持。 拥有多对多关系

加入查询。在对父类执行查询时,不能在筛选器中使用子实体的字段。请注意,您可以在查询中使用键直接测试父级的关系字段

JDOQL分组和其他聚合查询

多态查询。不能通过查询类来获取子类的实例。每个类在数据存储中由一个单独的实体类表示

@PersistenceCapable注释的IdentityType.DATASTORE。仅支持IdentityType.APPLICATION

当前存在一个错误,阻止将超类上的持久字段保存到数据存储中。这将在将来的版本中修复