[英]Hibernate self ManyToMany save problem
I have a class Node Node.java我有一个 class 节点Node.java
public class WebPage implements BusinessObject {
@Id
private Long id;
@ManyToMany
@JoinTable(name = "childnodes")
private Set<WebPage> references; // nodes contained by this node
}
My requirements:我的要求:
I want to do something like this:我想做这样的事情:
Node A -> Node D节点 A -> 节点 D
Node B -> Node E节点 B -> 节点 E
All steps run OK except the 5th one.除第 5 步外,所有步骤都运行正常。 I have an exception:
Unique index or primary key violation:
How can i tell Hibernate to DO NOT try to insert Node C but instead update it !我有一个例外:
Unique index or primary key violation:
我如何告诉 Hibernate 不要尝试插入节点 C 而是更新它!
You didn't provide the code which tries to create all entities.您没有提供尝试创建所有实体的代码。 However, the flow would be something like,
然而,流程会是这样的,
cascade-insert
cascade-insert
保存节点 BThe problem was not on Hibernate behalf but on a bug in my code:\问题不在 Hibernate 上,而是在我的代码中的一个错误:\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.