带有休眠的实体的映射中的重复列

时间:2019-05-15 08:03:00

标签: hibernate

我正在使用休眠模式来做一个项目。而且我的映射存在问题。 我收到此错误:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.el_dao.entity.Save column: idModel (should be mapped with insert="false" update="false")

这是实体:

@Embeddable
public class SaveId implements Serializable{

    private static final long serialVersionUID = 1L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "login", referencedColumnName = "login")
    private User login;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "idStep", referencedColumnName = "idStep", insertable=false, updatable=false),
        @JoinColumn(name = "idModel3", referencedColumnName = "idModel", insertable=false, updatable=false),
        @JoinColumn(name = "idPart2", referencedColumnName = "idPart", insertable=false, updatable=false),
        @JoinColumn(name = "idPiece", referencedColumnName = "idPiece", insertable=false, updatable=false)
    })
    private Step idStep;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "idPart", referencedColumnName = "idPart", insertable=false, updatable=false),
        @JoinColumn(name = "idModel", referencedColumnName = "idModel", insertable=false, updatable=false)
    })
    private Part idPart;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idModel", referencedColumnName = "idModel", insertable=false,  updatable=false)
    private Model idModel;

以及使用上一个实体的实体:

@Entity
@Proxy(lazy = false)
@Table(name = "save", schema = "public")
public class Save implements Serializable{

    private static final long serialVersionUID = 1L;

    /**
     * Save's id
     */
    @EmbeddedId
    private SaveId saveId;

我已经使用了几种选择,但没有结果,例如在false中添加insert和update。

1 个答案:

答案 0 :(得分:0)

根据休眠文档:

  

嵌入对象的每个持久属性或字段是   映射到实体的数据库表。

因此,在您的情况下,实体Save将有两个名为idModel的列,这就是为什么休眠的原因。您应该更改“连接列”之一的名称,例如:

 @ManyToOne(fetch = FetchType.LAZY)
 @JoinColumn(name = "idModel2", referencedColumnName = "idModel", insertable=false,  updatable=false)
    private Model idModel;