应用服务引擎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;
}

我然后使一个新的对象,像这样:

的PersistenceManager PM = PMF.get()getPersistenceManager();  pm.makePersistent(新预订( “乔治奥威尔”, “1984”));

我可以查询使用查询这样新的对象:

查询的查询= pm.newQuery(+ Book.class.getName “从选择”()+ “其中作者== PARAM”);  query.declareParameters( “字符串PARAM”);  列出结果=(列表)query.execute( “乔治奥威尔”);

此返回对象,因为我上查询书所定义的字段“作者”。

然而,这并不工作:

查询的查询= pm.newQuery(+ Book.class.getName “从选择”()+ “其中标题== PARAM”);  query.declareParameters( “字符串PARAM”);  列出结果=(列表)query.execute( “1984”);

,则抛出其中规定不存在字段“标题”,即使通过此点在派生类产品定义的例外。

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

看起来好像从继承类字段不是在储存库查询可用的。

这是实际上可能的所述语法的变体,或者与注解?

有帮助吗?

解决方案

自: http://code.google.com/appengine /docs/java/datastore/usingjdo.html

JDO的不支持的功能

JDO接口的以下功能不是由应用程序引擎实现支持:

无主的关系。您可以使用明确的键值实现无主的关系。 JDO对无主的关系语法可能在将来的版本中支持。 拥有的多对多的关系。

“加入” 的查询。父样进行查询时,您不能在过滤器中使用子实体的领域。请注意,您可以直接在查询中使用的一个关键测试父的关系字段。

JDOQL分组和其他聚合查询。

多态查询。您不能执行类的查询来获取子类的实例。每类由一个单独的实体类型数据存储区中表示。

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

<强>目前防止防止在超类的持久字段被保存到数据存储区中的错误。这将被固定在将来的版本。

其他提示

该查询,使用DataNucleus将与任何我们支持其它的数据存储(例如RDBMS,XML,Excel等),应确实允许在超类字段;查询有效JDOQL。如果他们不工作,GAE / J则报告该问题在谷歌的问题跟踪,但肯定有一个问题,有关于继承已 http://code.google.com/p/datanucleus-appengine/issues/列表

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top