Hi everybody,

I'm struggling with a strange problem with JDO.
I've got two PersistenCapable classes, one having a Collection of
objects of the second, something like this:

class First {
 @Persistent
 @PrimaryKey
 Long id;

 @Persistent(mappedby="owner")
 ArrayList<Second> list = new ArrayList<Second>();

 ArrayList<Second> getList() {
  if (list == null)
   list=new ArrayList<Second>();
  return list;
 }

...
}

class Second {
 @Persistent
 @PrimaryKey
 Key id;

 @Persistent
 First owner;

 First getOwner() {
  if (owner==null)
   owner = new First();
  return owner;

 ...
}


In another class I need to print the owner of all my First objects, so
I do:
First obj = ...;
ArrayList<Second> list = obj.getList();
for (Second s : list) {
 System.out.println(s.getOwner());
}

In this loop, I find some Second object having null owner, and I
cannot understand why.
Now I have several questions about my data modelling:
1) Do I need to mark any field with (defaultFetchGroup = "true")
annotation?
2) Does the check on null object (e.g. if (owner==null) owner = new
First();) in the getter methods results in any strange behavior?
3) Does the assignment on definition of objects (e.g.
ArrayList<Second> list = new ArrayList<Second>();) results in any
strange behavior?
4) Do I need to add any other annotation to owner field of Second
class?

Thank you very much for your help!!
Best regards
cghersi

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to