I have a One-To-Many owned relationship from Parent to Child classes.
I add the child to the parent and persist the parent in DB. Later if I
change the state of parent and children and do em.merge(parent) , the
parent gets updated but the Children don't ! I am using
cascade=CascadeType.ALL.

Note that
1. I am using datanucleus.DetachOnClose = true (though I believe that
is not the issue here)
2. This doesn't happen with OneToOne relationship
3. I am using API 1.2.2. Am not using 1.2.5 right now for
compatibility reasons(my old code doesn't work with the new release.
Will bug you all for that another time)

Why is the update on parent not getting cascaded to the children? I
don't want to manually update each child. I would ideally want to call
merge on the topmost element and let each node in the subgraph get
updated through cascading.  JPA spec and GAE's documentation both
state it should get cascaded if cascade=CascadeType.ALL But that
doesnt seem to be the case here

Please let me know if I am missing something. Or is this a bug/known
limitation?

p.s. In case one would like to look at the sample code for more
clarity then here it is

@Entity
public class Parent {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        protected Key id;
        @OneToMany(cascade=CascadeType.ALL)
        List<Child> children;
        public List<Child> getChildren() {
                return children;
        }
        public void setChildren(List<Child> children) {
                this.children = children;
        }
        public void addChild(Child child) {
                if(children == null)
                        children = new ArrayList<Child>();
                children.add(child);
        }
}

@Entity
public class Child {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        protected Key id;
        private String x;
        public String getX() {
                return x;
        }
        public void setX(String x) {
                this.x = x;
        }
}

Here is the test Case.
                //Persist new parent with single child
                Parent parent = new Parent();;
                Child child = new Child();
                parent.addChild(child);
                DBUtil.persist(parent);//make sure that em.close() is called in 
both
DBUtil.update and persist()

                //Update the child;
                child.setX("testing");
                //update the parent
                DBUtil.merge(parent);//should cascade and update the children 
too.

               //Now the test cases
               Parent dbParent = ... ;//fetch parent object from DB
               //child's x should be equal to "testing". But it is
null
                assertTrue(dbParent.getChildren(0).getX() == null) ;//
Passes !!

                //now if i update the child directly then of course it
gets updated in DB too.
               //And the test case mentioned above passes
                DBUtil.merge(child);

                Parent dbParent = ... ;//fetch parent from DB
                //First child's x should be equal to "testing"
                assertTrue(dbParent.getChildren(0).getX()) ;// Pass
--~--~---------~--~----~------------~-------~--~----~
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