views:

28

answers:

0

I know there are already some posts regarding this subject, but although I tried using them as a reference, I am still stuck. I have a persistent class as follows:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class GameObject implements IMySerializable{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
protected Key m_databaseKey;

@NotPersistent
private final static int END_GAME_VAR = -1000;

@Persistent(defaultFetchGroup = "true")
protected GameObjectSet m_set;

@Persistent
protected int m_databaseType = IDatabaseAccess.TYPE_NONE;

where GameObjectSet is:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@FetchGroup(name = "mySet", members = {@Persistent(name = "m_set")}) 
public class GameObjectSet {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;

@Persistent
private Vector<GameObjectSetPair> m_set;

and GameObjectSetPair is:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class GameObjectSetPair {    

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;

@Persistent
private String key;
@Persistent(defaultFetchGroup = "true")
private GameObjectVar value;

When I try to fetch the entire structure by fetching the GameObject, the set doesn't have any elements (they are all null) I tried adding the fetching group to the PM, but to no avail. This is my fetching code

    Vector<GameObject> ret = new Vector<GameObject>();
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.getFetchPlan().setMaxFetchDepth(-1);
    pm.getFetchPlan().addGroup("mySet"); 
    Query myQuery = pm.newQuery(GameObject.class);
    myQuery.setFilter("m_databaseType == objectType");
    myQuery.declareParameters("int objectType");
    try {
        List<GameObject> res = (List<GameObject>)myQuery.execute(objectType);
        ret = new Vector<GameObject>(res);
        for (int i = 0; i < ret.size(); i++) {
            ret.elementAt(i).getSet();
            ret.elementAt(i).getSet().touchSet();
        }
    } catch (Exception e) {
    } finally {
        pm.close();
    }

Does anyone have any idea?

Thanks

Mike