java—使用spirng jpa从同一个表Map两对元素

ezykj2lf  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(318)

我想为图形创建一个sql数据库。我的想法是为图、节点和边创建一个表。每个图都有一个节点和边的列表。每个节点都有进入该节点的边的列表和从该节点出来的边的列表。每一条边都有它从哪个节点出来和进入哪个节点的信息。我得到一个错误-“实体Map中的重复列:graph.data.entity.edge列:node\u id(应该用insert=“false”update=“false”Map)”。我不应该加入node\u id列?当使用@joincolumn for tonode时,我应该使用insert=“false”update=“false”吗?
我的代码:
边缘.java

@Entity
public class Edge extends AbstractEntity {

    @NotNull
    @ManyToOne
    @JoinColumn(name = "node_id")
    private Node fromNode;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "node_id")
    private Node toNode;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "graph_id")
    private Graph graph;

    @NotNull
    private int weight;

节点.java

@Entity
public class Node extends AbstractEntity {

    private String name;

    @OneToMany(mappedBy = "fromNode", fetch = FetchType.EAGER)
    private List<Edge> outEdges = new ArrayList<>();

    @OneToMany(mappedBy = "toNode", fetch = FetchType.EAGER)
    private List<Edge> inEdges = new ArrayList<>();

    @ManyToOne
    @JoinColumn(name = "graph_id")
    private Graph graph;

图形.java

@Entity
public class Graph extends AbstractEntity {

    private String name;

    @OneToMany(mappedBy = "graph", fetch = FetchType.EAGER)
    private List<Node> nodes = new ArrayList<>();

    @OneToMany(mappedBy = "graph", fetch = FetchType.EAGER)
    private List<Edge> edges = new ArrayList<>();

'''

0aydgbwb

0aydgbwb1#

好吧,就在我发布问题后,我明白我做错了什么。我不得不简单地重命名列,这些列是连接列的效果

相关问题