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) {
PersistenceManage开发者_如何学JAVAr 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?
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.
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)
精彩评论