Hibernate Mapping Exception : Repeated column in mapping for entity

懵懂的女人 提交于 2019-11-28 12:05:51

have you set the collection in Employee as inverse?

<bag name="emails" inverse="true">
  <key column="EMPLOYEE_ID" not-null="true">
  ...
</bag>

For those who are using annotations to solve this, the classes should look like this:

@Entity
public class Email {

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private int intEmailID;

    @Column(insertable = false, updatable = false)
    private int employeeId;

    @ManyToOne
    private EmailType emailType;

    @ManyToOne
    @JoinColumn(name="employeeId")
    private Employee employee;

    // Getters and Setter
}


@Entity
public class Employee {

    @Id
    private int id;

    @OneToMany(cascade = {CascadeType.ALL}, mappedBy="employeeId")
    @PrimaryKeyJoinColumn
    private List<Email> emailList;

    public void setEmailList(List<Email> emailList) {
        this.emailList = emailList
    }

    public List<Email> getEmailList() {
        return emailList;
    }

    // Rest of getters and setters

}
Sajan Chandran

I think you have mapped Employee to Email using oneToMany relation. If yes its nothing wrong but you have to make sure you can insert and update only in one direction

should be mapped with insert="false" update="false" in Employee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!