I've had trouble with the .getById methods, so I do it like this,
which seems to work reliably:

                query = pm.newQuery(MyClass.class);
                query.setFilter("_ID == :keyList");  //_ID is the PK

                List<MyClass> results = (List<MyClass>)query.execute(Keys);  //
Keys is List<key>


On May 24, 2:19 am, Ravi <[email protected]> wrote:
> Hi,
> I have a list of Key and i want to get Entity for all these key using
> JDO.
> Is it possible in JDO? Having a hard time to search through internet
> and not finding it.
> Tried using pm.getObjectsById(Collection), but it says Object not
> found with keys present in the  list. I wrote following code for this
>
> PersistenceManager pm =
> DbSessionManager.getInstance().startDbSession();
>         List<Key> keyList = new ArrayList<Key>();
>         Key oneKey = KeyFactory.createKey("User", 9);
>         keyList.add(oneKey);
>         List<User> users = (List<User>)pm.getObjectsById(keyList); (Note:
> s after object)
>
> abovce code throws Exception that User(9) not found but it does exists
> in datastore and if i do
>
> User users = (User)pm.getObjectById(oneKey);(Note: no s after object)
>
> it returns the User(9)
>
> I also tried using Low level API like this and it works, but only
> problem is that it doesnt return its owned properties(see User class
> at the end, openIds are not returned and its always null, even though
> it does exists).
>
> public Map<Key, Entity> getObjectsById(List<Key> ids) throws
> AppException {
>         DatastoreService ds =
> DatastoreServiceFactory.getDatastoreService();
>          Map<Key, Entity> data = ds.get(ids);
>         return data;
>
> }
>
> class User{
> Key id;
> String firstName;
> String lastName;
> List<OpenId> openIds;
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" 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 
> athttp://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" 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-java?hl=en.

Reply via email to