App Engine - Query using class member as parameter

I have a simple class matching the details below:

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

 @Persistent
 public type t;
...
}

      

I am trying 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 hits shown by google that I have found so far recommend:

  • Use query.declareImports to specify the ieql.declareImports class ("com.test.zach.SimpleCategory.type");
  • Specify the full name of SimpleCategory in declareParameters

None of these suggestions worked. By removing the .type and recompiling, I can check that declareParameters can see SimpleCategory just fine, it just can't see SimpleCategory.type, even though the rest of the method is fully visible to it.

What am I missing?

+2


a source to share


2 answers


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



q.setFilter("t == :categoryType");
List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type)

      

0


a source


Have you rejected ( ...

) whether declared yourself public static enum type

@PersistenceCapable

. If not, it might explain why the query parser cannot resolve the class reference type

.



+1


a source







All Articles