我不明白为什么我仍然得到hibernate.MappingException:

Repeated column in mapping for entity: PanelCategoryOption column: category_id (should be mapped with insert="false" update="false")

PanelCategoryOption映射

@Entity
@Table(name = "eq_panel_category_option")
public class PanelCategoryOption {

    @EmbeddedId
    private PanelCategoryOptionId id;
}


PanelCategoryOptionId映射

@Embeddable
public class PanelCategoryOptionId implements Serializable {

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumns({
                @JoinColumn(name = "panel_id", referencedColumnName = "panel_id"),
                @JoinColumn(name = "category_id", referencedColumnName = "category_id")})
        private PanelCategory panelCategory;

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumns({
                @JoinColumn(name = "category_option_id", referencedColumnName = "id", insertable = false, updatable = false),
                @JoinColumn(name = "category_id", referencedColumnName = "category_id", insertable = false, updatable = false)})
        private CategoryOption categoryOption;

}


架构图

java - 通过多个映射为实体映射的重复列-LMLPHP

最佳答案

为什么在PanelCategoryOption表中有category_id参考。
这不是规范化的数据库设计,因为它不满足“第二范式”形式。尝试更新您的数据库设计。

另外,如果您不想更改数据库设计,则需要进行以下更改,

  @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
            @JoinColumn(name = "category_option_id", referencedColumnName = "id", insertable = false, updatable = false) })
    private CategoryOption categoryOption;

 @JoinColumns({
                @JoinColumn(name = "category_id", referencedColumnName = "category_id", insertable = false, updatable = false)})
 private Category category;

07-24 21:50