我定义了一个具有 Long primary key 的基类,就像这样。
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public class ModelBase implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
和其他 pojo 扩展了 ModelBase。当我像这段代码一样被jdoql查询时
public List<PersonalSetting> getByIds(Long... Ids) {
Query query = getQuery();
query.setFilter("id ==:id");
return (List<PersonalSetting>) query.execute(Ids);
}
但它只是给了我一个例外。
java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to com.google.appengine.api.datastore.Key
我发现 Key 类有“Id”字段,但我不能像“id.id == :id”那样访问它。有人能告诉我如何解决吗?非常感谢!