views:

175

answers:

1

Hi,

can JDO fetch all children of a database model at once? Like:

class Parent {
 @Persistent(mappedBy="parent") 
 private Set<Children> children;
}

class Children {
 @Persistent
 private Parent parent;
 @Persistent
 private String name;
}

In my case, I have a large number of Parents which I fetch at once. Accessing their children then takes a lot of time because they are fetched lazily. Does JDO (Datanucleus) support their fetching at once, togehter with the Parents?

I also tried to fetch all Children independantly with another quey and put them into the Level2 cache afterwards, but still they are fetched (maybe jdo doesn't know about their relationship? Because the ForeignKey (parent-id) hasn't been fetched at first?)

Any ideas how to read the data structure faster?

Cheers,

Jan

+1  A: 

Are you using Fetch Groups? Your Child classes are probably not in the default fetch group.

When an object is retrieved from the datastore by JDO typically not all fields are retrieved immediately. This is because for efficiency purposes only particular field types are retrieved in the initial access of the object, and then any other objects are retrieved when accessed (lazy loading). The group of fields that are loaded is called a fetch group

Peter Recore
I use FetchGroups but as far as I unserstood they do not control what is fetched at once but only what is (for example) detached. Do you agree? I don't want to detach the objects. I don't need it in the special case above. (Also, detaching doesn't fetch all children of a collection at once, too)
Jan
Fetch plans apply to both attach/detach *AND* what is fetched at once. another quote from the same page i linked to: "The FetchPlan applies not just to calls to PersistenceManager.getObjectById(), but also to PersistenceManager.newQuery(), PersistenceManager.getExtent(), PersistenceManager.detachCopy and much more besides. "
Peter Recore