Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌应用引擎java jpa一对多删除_Java_Google App Engine_Jpa - Fatal编程技术网

谷歌应用引擎java jpa一对多删除

谷歌应用引擎java jpa一对多删除,java,google-app-engine,jpa,Java,Google App Engine,Jpa,在GoogleAppEngineJavaJPA一对多关系中,如何删除子元素。 比如说 Class Parent{ // key defined here @OneToMany(cascade=CascadeType.ALL, mappedBy="parent") private List<Child> childs = null; . . . } Class child{ //key defined here too @ManyToOne private Par

在GoogleAppEngineJavaJPA一对多关系中,如何删除子元素。 比如说

Class Parent{
   // key defined here

   @OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
   private List<Child> childs = null;
.
.
.
}

Class child{
//key defined here too
@ManyToOne
private Parent parent;
.
.
.
}
现在我想删除child 1和2,并添加一个新的child 3

Parent p=//getParent
p.setChilds(new ArrayList<Child>())//remove all older childs
parent.getChilds().add(new Child(3));//adding new child 3
.
.
Parent p=//getParent
p、 setChilds(new ArrayList())//删除所有旧的childs
parent.getChilds().add(新子级(3))//添加新的孩子3
.
.
但当我再次找到同一个父母时,我有了所有的3个孩子,但不仅仅是3个孩子

谁能给我指路吗

谢谢, Ramesh.V可能会

parent.getChilds().clear();

因为这样可以避免删除和重新创建列表,并且还可以解决一些GAE问题。“child”的复数形式是“children”

您可以尝试从拥有方删除该关系,在本例中为Child#parent。因此,对于父集合中的每个子元素,请尝试:删除子元素或将父元素设置为null。比如:

Parent p = //getParent
List<Child> children = p.getChildren();
for (Child c : children) {
    c.setParent(null);
}

children.clear();
children.add(new Child(3));
Parent p=//getParent
List children=p.getChildren();
儿童(c:儿童){
c、 setParent(空);
}
儿童。清除();
儿童。添加(新儿童(3));

很抱歉没有工作。。。但清除或设置一个新的空对象在工作中并没有什么不同。。。
Parent p = //getParent
List<Child> children = p.getChildren();
for (Child c : children) {
    c.setParent(null);
}

children.clear();
children.add(new Child(3));