AppEngine 1.2.2. I define a class Product like so:
@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;
}
I define a derived class Book like so:
@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;
}
I then make a new object like so:
PersistenceManager pm = PMF.get().getPersistenceManager(); pm.makePersistent(new Book("George Orwell", "1984"));
I can query for this new object using a query like:
Query query = pm.newQuery("select from " + Book.class.getName() + " where author == param"); query.declareParameters("String param"); List results = (List) query.execute("George Orwell");
This returns the object, because I am querying a field 'author' defined on Book.
However this doesn't work:
Query query = pm.newQuery("select from " + Book.class.getName() + " where title == param"); query.declareParameters("String param"); List results = (List) query.execute("1984");
It throws an exception which states there is no field 'title', even through this is defined on the derived class 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
It seems as if fields from inherited classes are not available in the Datastore queries.
Is this in fact possible with a variation on the syntax, or with annotations?