Hi,
I'm trying to use default fetch groups to obtain fields at once (not
on demand) in my entity:

public class Survey {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true")
    private String idSurvey;
    @Persistent
    private String name;
    @Persistent
    private Date dateFrom;
    @Persistent
    private Date dateUntil;
    @Persistent
    private String author;
    @Persistent(mappedBy = "survey", defaultFetchGroup = "true")
    private List<Response> responseList;
}

public class Response {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true")
    private String idResponse;
    @Persistent(defaultFetchGroup = "true")
    private Survey survey;
    //list of all Answers in this Response
    @Persistent(mappedBy="response", defaultFetchGroup = "true")
    private List<Answer> answerList;
}

I'm getting the entities with a method in a DAO class, so I need to
open and close the PM:

public Object getObjectByID(Class objectClass, String objectID) {
        PersistenceManager pm = PMFactory.get().getPersistenceManager
();
        Object o = null;
        try {
            o = pm.getObjectById(objectClass, objectID);
            pm.retrieve(o);
        } catch (JDOException jdoe) {
            jdoe.printStackTrace();
        } finally {
            //pm.close();
        }
        return o;
    }

When I fetch a Survey I can access the responseList and all fields in
Responses in the list. But when I fetch a Response, although I can see
the Survey (I'm using debugger in NetBeans to watch the variables),
every field of the Survey (except surveyID) is null, even if it has
been set before. So basically I can access child's fields after
obtaining the parent, but not via versa.

if I change the code in DAO to :

o = pm.getObjectById(Response.class, responseID);
pm.retrieve(o.getSurvey());

it works. Also, I could make it with not closing the PM - when the
fields are accessed they are being refreshed. What is happening? Thank
you!
--~--~---------~--~----~------------~-------~--~----~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to