I have used the above mentioned solution for my many to many
relations. Now if I want to get all the entities of type Entity2 for
one entity of type Entity1 I query the ManyToManyLink with the key of
Entity1. As a result I get a list of keys for Entity2. Now how do I
query Entity2 to get all the instances for my list of keys in one go?
I ended up in querying Entity2 for every single key I have in my list
which is surely not acceptable. Any ideas?

On 7 Jun., 21:54, Ian Marshall <[email protected]> wrote:
> Hi Anna,
>
> There are various ways to approach this (others may well suggest other
> (better?) ones....
>
> 1.  Expose your encoded key strings using code like:
>
>   @PrimaryKey
>   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>   @Extension(vendorName="datanucleus", key="gae.encoded-pk",
> value="true")
>   private String sEncodedKey;
>
>   // Optional (see my way 2 below)
>   @Persistent
>   @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
>   private Long loID;
>
>   public String getEncodedKey()
>   {
>     return sEncodedKey;
>   }
>
>   // Optional (see my way 2 below)
>   public Long getID()
>   {
>     return loID;
>   }
>
> 2.  Continue with using encoded primary key strings (mine are
> automatically generated by the datastore for each entity at first-
> persistence-time) and then expose the entity's Long ID value (again,
> mine are automatically generated by the datastore for each entity at
> first-persistence-time) using:
>
>   @Persistent
>   @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
>   private Long loID;
>
>   public Long getID()
>   {
>     return loID;
>   }
>
> Beware that in this case, the Long ID values are not the full key,
> just a summary: you will need a full chain starting with the entity
> group parent and working down through the children to your entity
> (unless your entity is the parent of its entity group). I do find
> entities by (Long) ID, but need IDs of entity group ancestors to get
> this to work.
>
> 3.  Use Long IDs as your keys. I do not do this any more because of
> previously-existing bugs which I worked around by using encoded key
> strings and also to maintain some portability to outside of BigTable.
> I therefore cannot speak about this from recent experience.
>
> I hope that this helps,
>
> Ian
>
> On Jun 7, 8:29 pm, Anna <[email protected]> wrote:
>
> > Thank you very much Ian! I've implemented your solution but now I
> > struggle with adding a Link to the database: A record of entity 1 and
> > one of entity 2 are stored in the database. How can I get them out of
> > the database to put their keys into a new link? I don't know the keys
> > of both entities because I never use them to identify the objects (I
> > use Long values instead).
>
> > Regards, Anna

-- 
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