Dear Max,

I read the doc, but it seems to me that it describes 1-N
relationships, but there is a talk about 0-N relationships.

I have the same trouble and here is an example:

class BugReport {
 Key id;
 List<Comment> commentList;
}

class Comment {
 Key id;
}

So in this case I need 0-N relationship because when BugReport is
submitted, there are no comments yet.
But if I try to get list of BugReports or save second BugReort I'v got
an exception:

com.google.appengine.api.datastore.DatastoreNeedIndexException: no
matching index found.
        at
com.google.appengine.api.datastore.DatastoreApiHelper.translateError
(DatastoreApiHelper.java:35)
        at com.google.appengine.api.datastore.DatastoreApiHelper.makeSyncCall
(DatastoreApiHelper.java:56)
        at com.google.appengine.api.datastore.DatastoreServiceImpl
$PreparedQueryImpl.runQuery(DatastoreServiceImpl.java:342)
        at com.google.appengine.api.datastore.DatastoreServiceImpl
$PreparedQueryImpl.access$100(DatastoreServiceImpl.java:269)
        at com.google.appengine.api.datastore.DatastoreServiceImpl
$PreparedQueryImpl$1.iterator(DatastoreServiceImpl.java:303)
        at
org.datanucleus.store.appengine.DatastoreElementContainerStoreSpecialization.getChildren
(DatastoreElementContainerStoreSpecialization.java:99)
        at org.datanucleus.store.appengine.DatastoreFKListStore.listIterator
(DatastoreFKListStore.java:47)
        at
org.datanucleus.store.mapped.scostore.AbstractListStore.listIterator
(AbstractListStore.java:84)
        at org.datanucleus.store.mapped.scostore.AbstractListStore.iterator
(AbstractListStore.java:74)
        at org.datanucleus.sco.backed.List.loadFromStore(List.java:241)
        at org.datanucleus.sco.backed.List.toArray(List.java:591)
        at org.datanucleus.store.mapped.mapping.CollectionMapping.postInsert
(CollectionMapping.java:106)
        at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.runPostInsertMappingCallbacks
(DatastoreRelationFieldManager.java:225)
        at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.access
$300(DatastoreRelationFieldManager.java:49)
        at org.datanucleus.store.appengine.DatastoreRelationFieldManager
$1.apply(DatastoreRelationFieldManager.java:112)
        at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.storeRelations
(DatastoreRelationFieldManager.java:80)
        at
org.datanucleus.store.appengine.DatastoreFieldManager.storeRelations
(DatastoreFieldManager.java:804)
        at
org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject
(DatastorePersistenceHandler.java:231)
        at org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent
(JDOStateManagerImpl.java:3185)
        at org.datanucleus.state.JDOStateManagerImpl.makePersistent
(JDOStateManagerImpl.java:3161)
        at org.datanucleus.ObjectManagerImpl.persistObjectInternal
(ObjectManagerImpl.java:1298)
        at org.datanucleus.ObjectManagerImpl.persistObject
(ObjectManagerImpl.java:1175)
        at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent
(JDOPersistenceManager.java:669)
        at org.datanucleus.jdo.JDOPersistenceManager.makePersistent
(JDOPersistenceManager.java:694)

Is there a walk-around which can allow me to use 0-N relationships?

Thank you,
Anton Ananich

On Aug 15, 6:11 am, Max Ross <[email protected]> wrote:
> You may find this page 
> helpful:http://www.datanucleus.org/products/accessplatform_1_1/jdo/orm/one_to...
>
> The key point is that you need to set both sides of a bidirectional
> relationship.  Also, if you're accessing members directly (as in the below
> example) you need to annotate the class performing this access with
> @PersistenceAware.  Otherwise JDO can't see that you're modifying the fields
> and doesn't know it needs to perform any updates.  However, it's much easier
> to just always access members via setters and getters.
>
> Hope this helps,
> Max
>
>
>
> On Fri, Aug 14, 2009 at 4:31 PM, Dobromir <[email protected]> wrote:
>
> > Here's another test that fails and which gets to the heart of my
> > problem: how do I add a Child to a Parent that's already been saved?
>
> > �...@test  // FAILS - help!
> >  public void saveParentThenAddChild() throws Throwable {
> >     Child child = new Child();
> >    Parent parent = new Parent();
> >     savePojo(parent);
> >    assertNotNull(parent.key);
> >     parent.children = Lists.newArrayList(child);
> >    savePojo(parent);
> >     assertNotNull(parent.key);
> >    assertNotNull(child.key);  // THIS FAILS
> >  }
--~--~---------~--~----~------------~-------~--~----~
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