1

AppEngine 1.2.2。クラス Product を次のように定義します。

@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;
}

派生クラス Book を次のように定義します。

@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(new Book("ジョージ・オーウェル", "1984"));

次のようなクエリを使用して、この新しいオブジェクトをクエリできます。

Query query = pm.newQuery("select from " + Book.class.getName() + " where author == param"); query.declareParameters("文字列パラメーター"); List results = (List) query.execute("George Orwell");

Book で定義されたフィールド 'author' を照会しているため、これはオブジェクトを返します。

ただし、これは機能しません。

Query query = pm.newQuery("select from " + Book.class.getName() + " where title == param"); query.declareParameters("文字列パラメーター"); リスト結果 = (リスト) query.execute("1984");

これは、派生クラス Product で定義されていても、フィールド「タイトル」がないことを示す例外をスローします。

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

継承されたクラスのフィールドがデータストア クエリで使用できないようです。

これは、構文のバリエーションや注釈を使用して実際に可能ですか?

4

2 に答える 2

3

差出人:http ://code.google.com/appengine/docs/java/datastore/usingjdo.html

JDOのサポートされていない機能

JDOインターフェースの次の機能は、AppEngineの実装ではサポートされていません。

所有されていない関係。明示的なキー値を使用して、所有されていない関係を実装できます。所有されていない関係に対するJDOの構文は、将来のリリースでサポートされる可能性があります。多対多の関係を所有していました。

「結合」クエリ。親の種類でクエリを実行するときに、フィルターで子エンティティのフィールドを使用することはできません。キーを使用して、クエリで直接親の関係フィールドをテストできることに注意してください。

JDOQLのグループ化およびその他の集約クエリ。

ポリモーフィッククエリ。クラスのクエリを実行してサブクラスのインスタンスを取得することはできません。各クラスは、データストア内の個別のエンティティの種類で表されます。

@PersistenceCapableアノテーションのIdentityType.DATASTORE。IdentityType.APPLICATIONのみがサポートされています。

現在、スーパークラスの永続フィールドがデータストアに保存されないようにするバグがあります。これは将来のリリースで修正される予定です。

于 2009-09-19T12:48:46.127 に答える
1

DataNucleus をサポートしている他のデータストア (RDBMS、XML、Excel など) と一緒に使用するそのクエリは、実際にはスーパークラスのフィールドを許可する必要があります。クエリは有効な JDOQL です。それらが GAE/J で動作しない場合は、Google の問題トラッカーで問題を報告して ください。

于 2009-08-11T18:49:48.217 に答える