0

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!

Jump2cn
  • 13
  • 3
  • When I try to change the primary key to String type .It is happened again. My primary field is String but it said cannot be cast to Key .Why? How the contains method work , I will be crazy for this problem. – Jump2cn May 05 '12 at 11:41

1 Answers1

0

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

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • Thank you for reply.I just try the contains method,it not work.I got the same exception info.It look like they are in one kind.The version of gae sdk in my project is 1.6.4,and I has been change back to 1.6.3.1, it's not deferent. – Jump2cn Apr 02 '12 at 16:06
  • that is not the version of the persistence plugin, aka "datanucleus-appengine". What works in their plugin is one thing, I simply quote the JDO spec of what ought to work – DataNucleus Apr 02 '12 at 16:10
  • It's 1.0.10.final and the datanucleus-core is 1.1.5 . They all include by that two sdk version – Jump2cn Apr 02 '12 at 16:22
  • In another java file,the method just one id paramter, so I write like "id=="+id .And it's worke fine.Then I think if there is any options required first? – Jump2cn Apr 02 '12 at 16:51
  • 1.0.10.final is very old. There is a 2.0.0-final – DataNucleus Apr 03 '12 at 08:04