Hi,
I am having problem with updating an owned one-to-many relationship.
It seems to me that the relationship is not updated when add a child
during update. The same during create is working fine.
Here is a sample code about which I am talking about,
Parent class:
@PersistenceCapable(detachable="true")
public class Parent {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String parentId;
@Persistent
List<Child> children;
public Parent(String parentId, List<Child> children) {
this.parentId = parentId;
this.children = children;
}
// ...
}
Child Class:
@PersistenceCapable(detachable="true")
public class Child {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String childId;
public Child(String childId) {
super();
this.childId = childId;
}
// ...
}
Test Class:
String parentId = "parentId3";
List<Child> children = new ArrayList<Child>();
children.add(new Child("childId1"));
Parent parent = new Parent(parentId, children);
System.out.println("--Create--");
persist(parent); // There is only one child now - childId1
System.out.println("--Update--");
parent = read(parentId);
parent.getChildren().add(new Child("childId2")); // There are
two
children - childId1, childId2
persist(parent);
System.out.println("--Verify--");
read(parentId); // ERROR: There is only one child - childId1
In the third step when I try to verify the existence of two children,
I am getting only one!.
Note: I am explicitly detaching the object in both read and persist
methods.
Any help regarding this will be much appreciated. I can zip the
complete code and send if needed.
Thanks,
Anoop
--
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.