Hibernate Mapping Exception : Repeated column in mapping for entity

后端 未结 3 1079
北海茫月
北海茫月 2020-12-11 01:36

There is a mapping exception for a particular entity. Cant figure out from where the problem is arising. I checked all the mappings 3 times from start to end. Still i am get

相关标签:
3条回答
  • 2020-12-11 02:20

    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
    
    }
    
    0 讨论(0)
  • 2020-12-11 02:34

    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

    0 讨论(0)
  • 2020-12-11 02:35

    have you set the collection in Employee as inverse?

    <bag name="emails" inverse="true">
      <key column="EMPLOYEE_ID" not-null="true">
      ...
    </bag>
    
    0 讨论(0)
提交回复
热议问题