views:

39

answers:

2

I have a simple class, relevant details below:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class SimpleCategory implements Serializable{
... 
 public static enum type{
  Course,
  Category,
  Cuisine
 }

 @Persistent
 public type t;
...
}

I am attempting to query all SimpleCategory objects of the same type.

public SimpleCategory[] getCategories(SimpleCategory.type type) {
 PersistenceManager pm = PMF.get().getPersistenceManager();

 try{
  Query q = pm.newQuery(SimpleCategory.class);
  q.setFilter("t == categoryType");
  q.declareParameters("SimpleCategory.type categoryType");
  List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type);
...
}

This results in a ClassNotResolvedException for SimpleCategory.type. The google hits I've found so far recommended to:

  • Use query.declareImports to specify the class i.e. q.declareImports("com.test.zach.SimpleCategory.type");
  • Specify the fully qualified name of SimpleCategory in declareParameters

Neither of these suggestions has worked. By removing .type and recompiling, I can verify that declareParameters can see SimpleCategory just fine, it simply cannot see the SimpleCategory.type, despite the fact that the remainder of the method has full visibility to it.

What am I missing?

+1  A: 

You elided (...) whether public static enum type itself is declared @PersistenceCapable. If it isn't, that might explain why the query parser isn't able to resolve a reference to the type class.

Bert F
The enumeration is not @PersistenceCapable. I thought that only classes and embedded classes were to be marked as @PersistenceCapable. The 2 books I have on this subject have little to say on this topic.Adding @PersistenceCapable to the enumeration has changed the error footprint slightly. I will debug later when I've cooled down a bit. Debugging app engine is the most willy nilly and frustrating set of libraries I have ever dealt with.
Error 454
@Zach - Sorry, I don't know whether that is even the problem or whether enums need to be @PersistenceCapable. I was simply suggesting another possibility to try. I feel your pain. I just got started with GAE JDO too and the rules and pitfalls are killing me too.
Bert F
A: 

Something that has seemed to work for me is writing the query string using an implicit parameter and not using the declareParameters() method.

q.setFilter("t == :categoryType");
List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type)
Stevko
Thanks, this seems to work well, I need to revisit the docs on declareParameters(), I think I'm missing something.
Error 454