首页 > 解决方案 > Hibernate - 如何删除关联表中的冗余列

问题描述

我有两个实体:Intersection 和 Agent。

生成的表intersection_agents具有树列:intersection_idagents_agents_idagents_intersection_idintersection_idagents_intersection_id

是多余 的。消除这种冗余的正确方法是什么?

编辑1:

交叉口.java

@Entity
public class Intersecion {

    @Id
    private String id;

    @OneToMay
    private Set<Agent> agents;

    ...

}

代理.java

@Entity
public class Agent {

    @EmbbededId
    private PrimaryKey key;

    @Embeddable
    public static class PrimaryKey {
        String intersectionId;
        Long agentId;
    }

}

标签: javamysqlhibernate

解决方案


推荐阅读