[appengine-java] Re: JDO: Null parent on some children objects

2010-08-31 Thread cghersi
ok, thanks.
The second answer is dictated by the fact that I don't want null
values to be returned from getter methods, otherwise I cannot safely
do an operation like:
mySecondObject.getTags().add(tag);
as I need to check if getTags() has returned null.
So, which is the best in your opinion between the two:

mySecondObject.getTags().add(tag1);
mySecondObject.getTags().add(tag2);
pm.makePersistent(mySecondObject);

AND

ListString tags = mySecondObject.getTags();
if (tags == null)
 tags = neww ArrayListString();
tags.add(tag1);
tags.add(tag2);
mySecondObject.setTags(tags);
pm.makePersistent(mySecondObject);

For the owner... I'm with you, it is an ugly thing to create a
parent from the child...

Thanks
cghersi

On 30 Ago, 16:52, Frederik Pfisterer pfiste...@gmail.com wrote:
 while if I understood your explanation I don't have to invoke
 pm.makePersistent() on mySeconObject, is it?

 - correct, it is automatically saved with the parent.

 The other answer depends on the use case, but it appears to be very
 bad style to produce an owner/parent in the child object... children
 in real life also don't usually generate their parents ;-)

 Fred

 On 27 Aug., 16:03, cghersi cristiano.ghe...@gmail.com wrote:



  Hi Frederik!

  Sorry for my ignorance, I tougth that the right way to save a Second
  object was:

  pm.makePersistent(mySecondObject);
  myFirstObject.getList().add(mySecondObject);
  pm.makePersistent(myFirstObject);

  while if I understood your explanation I don't have to invoke
  pm.makePersistent() on mySeconObject, is it?

  I also put in all my getter methods a check on null object, in that
  way:
  class Second {
  �...@persistent
  �...@primarykey
   Key id;
  �...@persistent
   First owner;
  �...@persistent
   ListString tags;

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

   ListString getTags() {
    if (tags==null)
     tags= new ArrayListString();
    return tags;
   }

   ...

  }

  Do I have to remove all the check of the type if (obj==null)
  obj=new...?

  Thank you very much for your help!

  Best
  cghersi

  On 27 Ago, 10:58, Frederik Pfisterer pfiste...@gmail.com wrote:

   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 cristiano.ghe...@gmail.com 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 penet...@gmail.com 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 cristiano.ghe...@gmail.com 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)
   ArrayListSecond list = new ArrayListSecond();

   ArrayListSecond getList() {
    if (list == null)
     list=new ArrayListSecond();
    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 = ...;
  ArrayListSecond 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.
  ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this 

[appengine-java] Re: JDO: Null parent on some children objects

2010-08-30 Thread Frederik Pfisterer
while if I understood your explanation I don't have to invoke
pm.makePersistent() on mySeconObject, is it?

- correct, it is automatically saved with the parent.

The other answer depends on the use case, but it appears to be very
bad style to produce an owner/parent in the child object... children
in real life also don't usually generate their parents ;-)

Fred


On 27 Aug., 16:03, cghersi cristiano.ghe...@gmail.com wrote:
 Hi Frederik!

 Sorry for my ignorance, I tougth that the right way to save a Second
 object was:

 pm.makePersistent(mySecondObject);
 myFirstObject.getList().add(mySecondObject);
 pm.makePersistent(myFirstObject);

 while if I understood your explanation I don't have to invoke
 pm.makePersistent() on mySeconObject, is it?

 I also put in all my getter methods a check on null object, in that
 way:
 class Second {
 �...@persistent
 �...@primarykey
  Key id;
 �...@persistent
  First owner;
 �...@persistent
  ListString tags;

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

  ListString getTags() {
   if (tags==null)
    tags= new ArrayListString();
   return tags;
  }

  ...

 }

 Do I have to remove all the check of the type if (obj==null)
 obj=new...?

 Thank you very much for your help!

 Best
 cghersi

 On 27 Ago, 10:58, Frederik Pfisterer pfiste...@gmail.com wrote:

  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 cristiano.ghe...@gmail.com 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 penet...@gmail.com 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 cristiano.ghe...@gmail.com 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)
  ArrayListSecond list = new ArrayListSecond();

  ArrayListSecond getList() {
   if (list == null)
    list=new ArrayListSecond();
   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 = ...;
 ArrayListSecond 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.
 ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@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.



[appengine-java] Re: JDO: Null parent on some children objects

2010-08-27 Thread Frederik Pfisterer
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 cristiano.ghe...@gmail.com 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 penet...@gmail.com 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 cristiano.ghe...@gmail.com 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)
    ArrayListSecond list = new ArrayListSecond();

    ArrayListSecond getList() {
     if (list == null)
      list=new ArrayListSecond();
     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 = ...;
   ArrayListSecond 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.
   ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@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.



[appengine-java] Re: JDO: Null parent on some children objects

2010-08-27 Thread cghersi
Hi Frederik!

Sorry for my ignorance, I tougth that the right way to save a Second
object was:

pm.makePersistent(mySecondObject);
myFirstObject.getList().add(mySecondObject);
pm.makePersistent(myFirstObject);

while if I understood your explanation I don't have to invoke
pm.makePersistent() on mySeconObject, is it?

I also put in all my getter methods a check on null object, in that
way:
class Second {
 @Persistent
 @PrimaryKey
 Key id;
 @Persistent
 First owner;
 @Persistent
 ListString tags;

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

 ListString getTags() {
  if (tags==null)
   tags= new ArrayListString();
  return tags;
 }

 ...
}

Do I have to remove all the check of the type if (obj==null)
obj=new...?

Thank you very much for your help!

Best
cghersi

On 27 Ago, 10:58, Frederik Pfisterer pfiste...@gmail.com wrote:
 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 cristiano.ghe...@gmail.com 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 penet...@gmail.com 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 cristiano.ghe...@gmail.com 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)
 ArrayListSecond list = new ArrayListSecond();

 ArrayListSecond getList() {
  if (list == null)
   list=new ArrayListSecond();
  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 = ...;
ArrayListSecond 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.
ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@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.



[appengine-java] Re: JDO: Null parent on some children objects

2010-08-26 Thread Diego Fernandes
Hi,
i may find something here 
http://code.google.com/intl/en/appengine/docs/java/datastore/relationships.html


[]'s
Diego


On 26 ago, 04:42, cghersi cristiano.ghe...@gmail.com 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)
  ArrayListSecond list = new ArrayListSecond();

  ArrayListSecond getList() {
   if (list == null)
    list=new ArrayListSecond();
   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 = ...;
 ArrayListSecond 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.
 ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@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.



[appengine-java] Re: JDO: Null parent on some children objects

2010-08-26 Thread cghersi
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 penet...@gmail.com 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 cristiano.ghe...@gmail.com 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)
   ArrayListSecond list = new ArrayListSecond();

   ArrayListSecond getList() {
    if (list == null)
     list=new ArrayListSecond();
    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 = ...;
  ArrayListSecond 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.
  ArrayListSecond list = new ArrayListSecond();) 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 google-appengine-j...@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.