자바 App Engine 데이터 저장소:객체의 상속된 클래스 필드를 쿼리하는 방법은 무엇입니까?
-
12-09-2019 - |
문제
앱엔진 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.makePercious(new Book("조지 오웰", "1984"));
다음과 같은 쿼리를 사용하여 이 새 개체에 대해 쿼리할 수 있습니다.
쿼리 쿼리 = pm.newQuery("select from " + Book.class.getName() + " where 작성자 == param");query.declareParameters("문자열 매개변수");결과 나열 = (목록) query.execute("조지 오웰");
Book에 정의된 'author' 필드를 쿼리하고 있기 때문에 개체가 반환됩니다.
그러나 이것은 작동하지 않습니다.
쿼리 query = pm.newQuery("select from " + Book.class.getName() + " where title == param");query.declareParameters("문자열 매개변수");결과 나열 = (목록) query.execute("1984");
파생 클래스 Product에 정의되어 있는 경우에도 '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
Datastore 쿼리에서는 상속된 클래스의 필드를 사용할 수 없는 것 같습니다.
실제로 구문을 변형하거나 주석을 사용하여 이것이 가능합니까?
해결책
에서: http://code.google.com/appengine/docs/java/datastore/usingjdo.html
JDO의 지원되지 않는 기능
JDO 인터페이스의 다음 기능은 App Engine 구현에서 지원되지 않습니다.
소유되지 않은 관계.명시적인 키 값을 사용하여 소유되지 않은 관계를 구현할 수 있습니다.소유되지 않은 관계에 대한 JDO의 구문은 향후 릴리스에서 지원될 수 있습니다.다대다 관계를 소유했습니다.
"가입" 쿼리입니다.상위 종류에 대해 쿼리를 수행할 때는 필터에서 하위 항목의 필드를 사용할 수 없습니다.키를 사용하여 쿼리에서 직접 상위 관계 필드를 테스트할 수 있습니다.
JDOQL 그룹화 및 기타 집계 쿼리.
다형성 쿼리.하위 클래스의 인스턴스를 가져오기 위해 클래스 쿼리를 수행할 수 없습니다.각 클래스는 Datastore에서 별도의 항목 종류로 표시됩니다.
@PersistenceCapable 주석에 대한 IdentityType.DATASTORE.IdentityType.APPLICATION만 지원됩니다.
현재 슈퍼클래스의 영구 필드가 데이터 저장소에 저장되는 것을 방지하는 버그가 있습니다.이 문제는 향후 릴리스에서 수정될 예정입니다.
다른 팁
우리가 지원하는 다른 데이터 저장소(예: RDBMS, XML, Excel 등)와 함께 DataNucleus를 사용하는 해당 쿼리는 실제로 슈퍼클래스의 필드를 허용해야 합니다.쿼리가 유효한 JDOQL입니다.GAE/J에서 작동하지 않으면 Google의 이슈 트래커에 문제를 보고하세요. 단, 이미 상속에 관한 문제가 있는 것은 확실합니다.http://code.google.com/p/datanucleus-appengine/issues/list