-2

I've a little problem with GQL for GoogleAppEngine. If i execute this query on my Datastore:

SELECT * FROM CoursePO ORDER BY createdDate DESC LIMIT 4;

it correctly shows me the response with maximum 4 results (tuple whatever as you want..). When i execute the same query in my Java Code, the result is different. Does anyone know why? I post below the method which does the same Query.

PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery("SELECT FROM " + CoursePO.class.getName() + " ORDER BY createdDate DESC LIMIT 4");
List<CoursePO> results = (List<CoursePO>)q.execute();
LOGGER.warning("Size: " + results.size()); //This size is greather than 4!! :-(
pm.close();
return results;

Thank you so much in advance

[EDIT] I would like to know, how downVote this question -.- Do you think is a stupid question? Do you think i'm wrong? Try it before judge!

[ADDED INFO] The result content is the same as the simple Query q = pm.newQuery(CoursePO.class); So, all the elements inside the Entity. The only different thing is that the clause ORDER BY DESC works perfectly, but not for LIMIT 4.

[EDIT]

GQL Syntax from Google App Engine

Aerox
  • 669
  • 1
  • 13
  • 28
  • What is the content of the array? Do you have duplicate elements? Something you've never seen before? Other? – Jose L Ugia Jun 15 '14 at 21:03
  • Sorry, the content is the same as the simple Query q = pm.newQuery(CoursePO.class); So, all the elements inside the Entity. The only different thing is that the clause ORDER BY DESC works perfectly, but not for LIMIT 4 – Aerox Jun 15 '14 at 22:44
  • @JoseLUgia, it was you which down vote my question? (Just to know..) – Aerox Jun 16 '14 at 12:54
  • It seems that you are missing the scope of the query (columns separated by comma or "*"). – Jose L Ugia Jun 16 '14 at 20:37
  • No, it throws an Exception if you write '*', in newQuery you have to omit it. In any case if my code not contains syntax errors it should not throws any exceptions or some kind of error as it really do. – Aerox Jun 17 '14 at 20:48
  • 1
    Ah wait, it's not really GQL, but JDOQL, which doesn't have any LIMIT modifier. Use RANGE instead. Try SELECT FROM ORDER BY createdDate DESC RANGE 0, 10. http://db.apache.org/jdo/jdoql_quickref.pdf – Jose L Ugia Jun 17 '14 at 21:14
  • 1
    Thank you @JoseLUgia ! It's perfectly working know! I don't know how they (Google) write GQL syntax (so, i think is a mistake (See my EDIT to the question) ), anyway your response is good and you can write it as accepted response ;-) I'll check it as better response! Thank you so much! – Aerox Jun 19 '14 at 07:33

1 Answers1

1

JDOQL doesn't have any LIMIT modifier. Use RANGE instead. Try SELECT FROM ORDER BY createdDate DESC RANGE 0, 10. http://db.apache.org/jdo/jdoql_quickref.pdf

Jose L Ugia
  • 5,960
  • 3
  • 23
  • 26