0

I am trying to retrieve an entity from my database using its id. I've tried using all kind of commands but the result stays the same , I always get an empty entity. I know the id is correct because I run a query on my database and receive this id.
this is how i receive the id from my database

Object course = courseList.get(0).getKey().getId();

I tried creating a key from that id and use

Key key = KeyFactory.createKey("courses", course);
db.get(key);    

even tried run a query on database with that key.I can see the the query is correct but I still receive an empty entity:

Query query = new Query("Courses").setFilter(Query.FilterOperator.EQUAL.of(Entity.KEY_RESERVED_PROPERTY, key));    

and also like that

Query query = new Query("Courses").setFilter(Query.FilterOperator.EQUAL.of("__Key__", key));    

I'm out of ideas ... what am I doing wrong? I know for sure this key exist.In debug mode I can see this key.I see it also in my database. thanks

4

1 回答 1

0

我从来没有过多地使用过 Java,但是从文档中这样的东西应该可以工作:

PersistenceManager pm = PMF.get().getPersistenceManager();
Courses c = pm.getObjectById(Cources.class, course);
于 2013-04-05T10:51:28.820 回答