이 블로그 검색

2011년 4월 2일 토요일

child


public Item load() {
    PersistenceManager pm = PersistenceManagerFactoryGetter.get().getPersistenceManager();
    List<Data> datas = new ArrayList<Data>();
    Data data0 = null;
    try {
        Query q = pm.newQuery(Data.class);
        datas = (List<Data>) q.execute();
        if (datas.size() > 0)
            data0 = pm.detachCopy(datas.get(0)); // get first item only

    } finally {
        pm.close();
    }
    return data0.item;  // always null !!!!!
}

Hi,
I encounter problems while trying to implement GWT JDO features. Let's say there is a Data object that contains an Item object. In the datastore this would create a one-to-one relationship.
The problem is that when I try to get the object from the datastore, the 'item' field is always null. Of course I put the object to the datastore that contains the initalized Item object (end of the listing). When viewing the datastore, both Data and Item entities do exist.
Do I manage the one-to-one relationship wrong? What else is needed? The same situation is when I try to create one-to-many relatioship (an array of Item's)
Thanks for any hints.

Child objects aren't loaded with their parents because they are lazily loaded. The query.execute() doesn't return the child fields. They are only loaded if you try to access it (with a data0.getItem(), for instance). In your case, your're trying to access the child object after you close the PersistenceManager, so they're aren't loaded.

댓글 없음:

댓글 쓰기