具有2个关系和1个枚举的Hibernate Embeddable Composite Key

时间:2018-06-15 12:17:34

标签: java hibernate

我尝试在复合键中引入3个字段(2个关系和1个枚举)。这是我的课程:

导出

@Entity
@Table(name = "mng_export")
public class Export {
    ....

    @OneToMany(mappedBy = "export", cascade = {CascadeType.ALL})
    @Setter
    private List<ExportGroup> exportGroups;

    ....

}

Export

ExportGroup

package com.xxx.portal.postintake.dao.model;
import lombok.*;
import nl.xxx.digipolis.portal.auth.Group;
import javax.persistence.*;

@Entity
@Table(name = "mng_export_group")
public class ExportGroup {

    @EmbeddedId
    private ExportGroupId exportGroupId = new ExportGroupId();

    @ManyToOne
    @MapsId("exportId")
    @JoinColumn(name = "export_id")
    @Getter
    @Setter
    private Export export;

    @ManyToOne
    @MapsId("groupId")
    @JoinColumn(name = "group_id")
    @Getter
    @Setter
    private Group group;

    @MapsId("availableType")
    @Enumerated(EnumType.STRING)
    @Getter
    @Setter
    private ExportAvailableType availableType;

}

ExportGroup

这实际上是Export和Group

之间的桥接表

ExportGroupId

package com.xxxx.portal.postintake.dao.model;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;

@Embeddable
public class ExportGroupId implements Serializable {

    public ExportGroupId() {
    }

    @Column(name = "export_id")
    @Getter
    @Setter
    private Long exportId;

    @Column(name = "group_id")
    @Getter
    @Setter
    private Long groupId;

    @Column(name = "available_type")
    @Enumerated(EnumType.STRING)
    @Getter
    @Setter
    private ExportAvailableType availableType;

}

我可以设法将它编码到这里。但这在启动tomcat时给了我一个例外,

Caused by: 
  org.hibernate.AnnotationException: 
   Unknown entity name: 
   com.greenvalley.portal.postintake.dao.model.ExportAvailableType

我该如何解决这个问题?

0 个答案:

没有答案