无法使用hibernate映射复合键

时间:2016-10-09 15:10:21

标签: hibernate

我是hibernate的新手;在我最近的任务中,我被要求创建m_department表并使用具有复合键的现有BSU_EMPLOYEE表(每个部门可以有多个员工)。当我尝试在第三个映射表“m_department_employees”中映射这两个实体时,我收到此错误。有人可以帮我吗?

  

** org.hibernate.AnnotationException:com.retalix.insync.mdmapi.model.DepartmentEntity.employees引用的com.retalix.insync.mdmapi.model.DepartmentEmployeeEntity未映射到单个属性*的referencedColumnNames(MemberInternalKey,EmployeeInternalKey) *

映射表m_department_employees结构

    [department_id] [int] NOT NULL,
    [MemberInternalKey] [int] NOT NULL,
    [EmployeeInternalKey] [int] NOT NULL

m_department表结构

enter image description here

BSU_EMPLOYEE表结构

enter image description here

用于m_department表的ENTITY CLASS

@Entity
@Table(name = "m_department")
public class DepartmentEntity extends BaseEntityDto {   


    @OneToMany(fetch=FetchType.EAGER)
    @JoinTable(name = "m_department_employees",joinColumns = @JoinColumn(name = "department_id"),inverseJoinColumns = {@JoinColumn(name = "MemberInternalKey",referencedColumnName="MemberInternalKey")
                                                                                                                      ,@JoinColumn(name = "EmployeeInternalKey",referencedColumnName = "EmployeeInternalKey")   })
    private Collection<DepartmentEmployeeEntity> employees = new ArrayList<DepartmentEmployeeEntity>();

BSU_EMPLOYEE的实体类

@Entity
    @Table(name = "BSU_EMPLOYEE")
    @AttributeOverrides({
        @AttributeOverride(name = "externalID", column =@Column(name="MemberInternalKey",insertable = false,updatable = false)),
        @AttributeOverride(name = "internalID", column =@Column(name="EmployeeInternalKey"))})


    public class DepartmentEmployeeEntity extends BaseEntityDto {    

        @EmbeddedId
        private DepartmentEmployeeIdClass idClass;

            @ManyToOne
        private DepartmentEntity departmentEntity;

COMPOSITE KEY CLASS

 @Embeddable
    public class DepartmentEmployeeIdClass implements Serializable {


        @Column(name = "MemberInternalKey" ,unique = false,nullable = false, insertable = true, updatable = true)
        private int memberInternalKey;


        @Column(name = "EmployeeInternalKey")
        private int employeeInternalKey;

0 个答案:

没有答案