Hi Santiago,

Please see the section of the docs titled "Getting an object by key":
http://code.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata.html#Getting_an_Object_By_Key

-Nick Johnson

On Wed, Apr 20, 2011 at 5:43 AM, Santiago Poli <[email protected]>wrote:

> 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!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>


-- 
Nick Johnson, Developer Programs Engineer, App Engine

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

Reply via email to