문제

I try to optimize my GAE. This is my model :

Game : id , status, players ... and List ;
Round : id , name, desc ... ;

I got relationships between Game and Round : 1-N

The problem is I can't request a Game without his all Round or specific field.

I have already tried this :

Query query = pm.newQuery(Game.class);
ArrayList<Game> allgame = new ArrayList<Game>();
query.setResult("id, status");
allgame.addAll((Collection<? extends Game>) query.execute());

and

Query query = pm.newQuery("SELECT id, status FROM com.ws.model.Game");
ArrayList<Object> allgame = new ArrayList<Object>();
allgame.addAll((Collection<? extends Object>) query.execute());

I'm using the PersistenceManagerFactory and JDO v1. I really want to reduce my read cost by not request all child (Round)

Thanks

도움이 되었습니까?

해결책

When an object is retrieved from the datastore by JDO, only the called fetch group is retrieved. Unindexed properties including Text and Blob are not retrieved by default. This means that serialized field values (as your Round objects) will not be retrieved by default. This is called lazy loading.*

To get only certain fieds you can use a query like this:

        query = pm.newQuery("SELECT status, players FROM " +
                Game.class.getName() + " WHERE xy == :xy);

Remember that in this case the fields you retrieve must be indexed.

Hope this helps.

*REF: Google App Engine Java and GWT Application Development

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top