Hi Jason,
many thanks for the response. Yes, I'm querying for an object and then
trying to add an option to it. I should have been clearer about that.
The code is basically:
Make temp = pm.getObjectById(Make.class, makeKey);
temp.getModels().add(model);
temp.getOptions().add(optionKey);
pm.makePersistent(temp);
In the above, optionKey is an Encoded String version of the option's
key.
Even with defaultFetchGroup = "true" as you suggested, the
"temp.getOptions().add(optionKey)" line will return a null pointer
exception as getOptions is returning null.
Many thanks in advance,
Dominic.
On Aug 14, 7:59 pm, "Jason (Google)" <[email protected]> wrote:
> Hi Dominic. I assume that you're querying for an object and then trying to
> add an option to it, but the datastore returns a null options field, even
> when there are options persisted.
> Can you try adding the List to the defaultFetchGroup using the following and
> see if that helps:
>
> @Persistent(defaultFetchGroup = "true")
> private List<String> options;
>
> - Jason
>
> On Thu, Aug 13, 2009 at 3:08 PM, Cioccas <[email protected]>wrote:
>
>
>
> > Hi all,
>
> > I'm having a problem with unowned collection. In my fictitious example
> > I have a Make, Model and Option.
>
> > A Make can have many Models (owned relationship) but an Option can
> > belong to either a Make or a Model (hence unowned). I'm using an
> > encoded String as a key (as I need to serialise these objects). I alve
> > also tried Long keys without success.
>
> > So, the class definitions look similar to below:
>
> > Make
> > ====
>
> > @PersistenceCapable(identityType = IdentityType.APPLICATION)
> > public class Make implements Serializable
> > {
> > �...@primarykey
> > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> > �...@extension(vendorName="datanucleus", key="gae.encoded-pk",
> > value="true")
> > private String key;
>
> > �...@persistent
> > private String name;
> > �...@persistent
> > private String description;
> > �...@persistent
> > private List<Model> models;
> > �...@persistent
> > private List<String> options;
>
> > Option
> > =====
>
> > @PersistenceCapable(identityType = IdentityType.APPLICATION)
> > public class Option implements Serializable, KeyedObject
> > {
> > �...@primarykey
> > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> > �...@extension(vendorName="datanucleus", key="gae.encoded-pk",
> > value="true")
> > private String key;
>
> > �...@persistent
> > private String name;
> > �...@persistent
> > private String description;
>
> > Now, the problem is that when I want to add a Make to a Model (owned
> > relationship) I can do the following:
>
> > make.getModels().add(model);
>
> > But I the issue is that I _can't_ to the following:
>
> > make.getOptions.add(option.getKey());
>
> > ... as getOptions() will always return null.
>
> > According to the documentation at:
>
> >http://code.google.com/appengine/docs/java/datastore/relationships.ht...
>
> > this is exactly how I should set up an unowned relationship: i.e. one
> > object should contain a set of "keys" for the relationships with the
> > unowned objects ("options" here). The problem is really, how to add
> > keys to these key collections as they are always null?
>
> > Regards,
> > Dominic.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---