-1

I am writing a cloud endpoint api using JDO to fetch a list of users based on the emailid. I am passing email id as a @Named parameter to the email and adding it to the query filter and i get the error message "Unexpected expression type while parsing query. Variables not supported by GAE (email)"

FYI, gae version is 1.8

@Api (name="MyAppname", version="v1")
public class PersonEndpoint {

public Person validate(@Named("email") String email, @Named("role") String role){
    .......

    PersistenceManager pm=getPersistenceManager();
    Query q = pm.newQuery(Person.class);

    q.setFilter(" email == emailParam && role == "+role);
    q.declareParameters("String emailParam");

    try{
        person=(Person)q.execute(email);
    }finally{
        q.closeAll();
        pm.close();
    }

    return person;
}

}

Any suggestions please?

Here is the Person class

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Person {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
    @Persistent
private String emailId;
    @Persistent
private String role;
    <getters and setters here>
}

The exception i see when i call the validate API

javax.jdo.JDOFatalUserException: Unexpected expression type while parsing query. Variables not supported by GAE (email)
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:498)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:252)
Vanitha R
  • 133
  • 2
  • 9
  • any exception has a stack trace, and a type for that matter. – DataNucleus May 30 '13 at 06:43
  • I see this exception "Unexpected expression type while parsing query. Variables not supported by GAE (email)" ... Is email not supported by gae? Can we not write a query to filter an entity by email ids? – Vanitha R May 30 '13 at 08:52
  • You still don't present basic info. You have a Person class ... and what is it ? The stack trace ? – DataNucleus May 30 '13 at 09:00
  • Have edited my question giving details of the Person class and the stack trace of the exception. Hope this is enough – Vanitha R May 30 '13 at 09:18

3 Answers3

1

You try a query referring to "email" yet this is not declared as a parameter to the query, nor is it a field of Person. Consequently you get an exception that your query is invalid. Perhaps your query was intended to be

"emailId == emailParam && role == "+role
DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • The emailParam is declared and is a field of Person Query q = pm.newQuery(Person.class); q.setFilter(" email == emailParam && role == "+role); q.declareParameters("String emailParam"); person=(Person)q.execute(email); – Vanitha R May 30 '13 at 10:31
  • "email" is not a field of Person (emailId is), and "email" is not a parameter (emailParam is) ... as already said – DataNucleus May 30 '13 at 10:36
  • Thanks for ur help but i am seeing a different error which i have posted below – Vanitha R May 30 '13 at 10:55
0

The issue is you are not correctly identifying the parameters.

change your code to this:

Query q = pm.newQuery(Person.class);
q.declareParameters("String emailParam, String roleParam");
q.setFilter(" emailId == emailParam && role == roleParam");
q.setUnique(true); // This is needed if only returning one object otherwise it returns a list

try{
    person=(Person)q.execute(emailId, role);
PSchuette
  • 4,463
  • 3
  • 19
  • 21
-2

I changed email to emailId and am not using an emailParam now since i am using the emailId as is passed into the api method. So the code now looks like

public Person validate(@Named("emailId") String emailId, @Named("role") String role){
     Query q = pm.newQuery(Person.class);
    q.setFilter(" email == "+emailId+" && role == "+role);
            person=(Person)q.execute();

}

Now i see a different error because of the @ in the email id. How do we pass such parameters to the query?

javax.jdo.JDOUserException: Portion of expression could not be parsed: @gmail.com && role == collector
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:519)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:230)
Vanitha R
  • 133
  • 2
  • 9
  • 3
    Stackoverflow is not for continually changing question, and you do NOT add an answer saying you changed something ... that is what updating the question is for. This question was answered, so you raise a new one with complete description of the problem. – DataNucleus May 30 '13 at 11:13