Search code examples
google-app-enginejdojdoql

GAE,JDO How to query primary key by Long/long type


I define a base class which have a Long primary key , just like this.

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public class ModelBase implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

and other pojo extends the ModelBase. When I was query by jdoql like this code

public List<PersonalSetting> getByIds(Long... Ids) {
    Query query = getQuery();
    query.setFilter("id ==:id");
    return (List<PersonalSetting>) query.execute(Ids);
}

but it just give me a exception.

java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to com.google.appengine.api.datastore.Key

I found the Key class have "Id" field, but I can't access it like "id.id == :id". Is anyone could tell me how to fix it? Thank you very much!


Solution

  • Invalid JDOQL. If you want to find an element in a collection you do ":ids.contains(id)"

    Obviously it would make sense to state what version of Googles persistence plugin you're using, and then the log/stacktrace