HIbernate 空指针 bindManytoManyInverseFk

HIbernate Null Pointer bindManytoManyInverseFk

我有一个非常简单的 Hibernate 关系,它给了我以下异常:

Unable to configure EntityManagerFactory
Caused by: java.lang.NullPointerException at org.hibernate.cfg.annotations.CollectionBinder.
bindManytoManyInverseFk(CollectionBinder.java:1370)

我不知道如何使用注释来映射它。

我的代码非常简单,只有 2 classes 和一个 Id class。

个人资料CLASS

@Entity
public class Profile {

    @Id
    private int profileId;

    @Column(nullable=false)
    private String name;

    @OneToMany(mappedBy="profile")
    @JoinTable(
        name="ProfileMetrics", 
        joinColumns={@JoinColumn(name="ProfileId")}
    )    
    private Set<Metrics> metrics = new HashSet<Metrics>();

    // Getters & Setters
}

指标CLASS

@Entity
@IdClass(MetricsPK.class)
public class Metrics implements Serializable {

    @Id
    private Profile profile;

    @Id
    private String moduleId;

    @Id
    private String metricId;

    @Column
    private Integer displayOrder;

    // Getters & Setters
}

ID CLASS

public class MetricsPK implements Serializable {

    private int profile;
    private String moduleId;    
    private String metricId;

    // Getters & Setters & Hashcode & Equals    
}

外键必须双向映射。

内部资料

@OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
private Set<Metrics> metrics = new HashSet<Metrics>();

内部指标

@ManyToOne
@JoinColumn(name = "PROFILE_ID")
private Profile profile;