Hi,

the problem is this line:
owner = new First();

Beware that the only way you should ever store a Second object is:
myFirstObject.getList().add(mySecondObject);
pm.makePersistent(myFirstObject);

since Second.owner is mapped it's automatically populated by the
persistance manager.

Hope this helps,
Fred


On 26 Aug., 17:38, cghersi <[email protected]> wrote:
> Hi Diego,
>
> thank you but unfortunately I strictly followed what stated in that
> page, and the result is the problem I posted!!
>
> Any other hint?
>
> Thank you very much,
> Best
> Cghersi
>
> On 26 Ago, 16:09, Diego Fernandes <[email protected]> wrote:
>
> > Hi,
> > i may find something 
> > herehttp://code.google.com/intl/en/appengine/docs/java/datastore/relation...
>
> > []'s
> > Diego
>
> > On 26 ago, 04:42, cghersi <[email protected]> wrote:
>
> > > 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