Hi,

Configuration:
- Appengine sdk 1.3.1

- 2 Entities: Indicator, Graph

/*
 * INDICATOR.java
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
@FetchGroup(name="graph", members = { @Persistent(name = "graph")})
public class Indicator {

        @PrimaryKey
        @Persistent
        private String code;

        @Persistent(defaultFetchGroup = "true", dependent = "true")
        private Graph graph;
}

/*
 * GRAPH.java
 */
public class Graph {

        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key id;

        @Persistent
        private String title;
}

/*
 * DAO
 */
public Indicator saveOrUpdate(Indicator newIndicator) {
                Indicator result;
                PersistenceManager pm =PMF.getPersistenceManager();

                try {

                        result = pm.makePersistent(newIndicator);
                        result = pm.detachCopy(result);

                } finally {
                        pm.close();
                }
                return result;
}

/*
 *  UNIT_TEST
 */
public void test() {

                Indicator withoutGraph = new Indicator("TEST");
                assertEquals(null, withoutGraph.getGraph());

                Indicator indicatorPersisted = dao.saveOrUpdate(withoutGraph);

                assertEquals(null, indicatorPersisted.getGraph());

                // create graph
                Graph graph = new Graph();
                graph.setTitle("Graphe TEST");

                // add graph
                indicatorPersisted.setGraph(graph);

                assertNotNull(indicatorPersisted.getGraph());

                Indicator indicatorPersisted =
dao.saveOrUpdate(indicatorPersisted);
        }

BUT, here what i got:
"Detected attempt to establish Indicator("TEST") as the parent of
Graph(3) but the entity identified by Graph(3) has already been
persisted without a parent.  A parent cannot be established or changed
once an object has been persisted.
org.datanucleus.store.appengine.DatastoreRelationFieldManager
$ChildWithoutParentException: Detected attempt to establish
Indicator("TEST") as the parent of Graph(3) but the entity identified
by Graph(3) has already been persisted without a parent.  A parent
cannot be established or changed once an object has been persisted.
        at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:
207)
        at org.datanucleus.store.appengine.DatastoreRelationFieldManager
$1.setObjectViaMapping(DatastoreRelationFieldManager.java:132)
        at org.datanucleus.store.appengine.DatastoreRelationFieldManager
$1.apply(DatastoreRelationFieldManager.java:111)
        at
org.datanucleus.store.appengine.DatastoreRelationFieldManager.storeRelations(DatastoreRelationFieldManager.java:
80)
        at
org.datanucleus.store.appengine.DatastoreFieldManager.storeRelations(DatastoreFieldManager.java:
955)
        at
org.datanucleus.store.appengine.DatastorePersistenceHandler.storeRelations(DatastorePersistenceHandler.java:
527)
        at
org.datanucleus.store.appengine.DatastorePersistenceHandler.updateObject(DatastorePersistenceHandler.java:
519)
..."


Here the doc:
http://code.google.com/intl/fr-FR/appengine/docs/java/datastore/relationships.html#Owned_One_to_One_Relationships
It says that:
"Similarly, if the Employee object has already been saved and the
related ContactInfo object is new, App Engine creates the ContactInfo
entity using the existing Employee entity as the parent."

Thanks!

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