Java App Engine Datastore: How to query fields of object's inherited classes?

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?

以上就是Java App Engine Datastore: How to query fields of object's inherited classes?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏