Get datastore element by id

212 views
Skip to first unread message

Santiago Poli

unread,
Apr 19, 2011, 3:43:18 PM4/19/11
to Google App Engine
Hello everyone. I have a problem when trying to find a single element
by id. The entity class is this:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Test{

@PrimaryKey
private String name;

..and so on.

In this case, the value "name" is acting like an id. I'm using this
query to find the element:

PersistenceManager pm =
PMF.get().getPersistenceManager();

Query q = pm.newQuery(Test.class);
q.setFilter("name == " + category_id);

//String query = "SELECT FROM " + JokeCategory.class.getName() + "
WHERE name == " + category_id;
JokeCategory category = (JokeCategory) q.execute();

return category;

But it doesn't retrieve any data. Also, it throws an exception:
java.lang.ClassCastException:
org.datanucleus.store.appengine.query.StreamingQueryResult cannot be
cast to com.santiagopoli.gapptest.domain.Test

The commented query also doesn't work.

I hope anyone can help me. Is a shame that something that basic is
difficult to achieve. In other sql implementations, it will be easy as
typing "select * from Test where id=<id>". Thanks!

Nick Johnson (Google)

unread,
Apr 21, 2011, 1:11:10 AM4/21/11
to google-a...@googlegroups.com
Hi Santiago,


-Nick Johnson


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.




--
Nick Johnson, Developer Programs Engineer, App Engine


test....@gmail.com

unread,
Apr 21, 2011, 1:57:38 AM4/21/11
to google-a...@googlegroups.com

--
Mobile message from Corporate Email powered by Remoba Inc.


Original Content Appended

Reply all
Reply to author
Forward
0 new messages