开发者

Hibernate self ManyToMany save problem

I have a class Node 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 :

  1. One node can reference many nodes.
  2. One node can reference it self.
  3. One node can be referenced by many nodes or not.

I want to do something like this :

  1. Node A -> Node B (Node A references Node B and so on)

  2. Node A -> Node C

  3. Node A -> Node D

  4. Node B -> Node E

  5. Node B -> Node C

All steps run OK except the 5th one. I have an exception : Unique index or primary key violation: How can i tell Hibernate to DO NOT try to insert Node C开发者_如何学C but instead update it !


You didn't provide the code which tries to create all entities. However, the flow would be something like,

  1. Create/Retrieve all nodes required for Node B
  2. Populate Node B with all those
  3. Save Node B with cascade-insert


The problem was not on Hibernate behalf but on a bug in my code :\

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜