如果与复合键有3个以上的关系,我可以使用@EmbeddedId吗?
关系
父母 - >孩子 - >孙子 - >曾孙
父
@Entity
@Table(name="mig_club_info")
public class MigGolfClub {
@Id @Column(name = "club_id")
private String club_id;
}
儿童
@Embeddable
public class MigCourseId implements Serializable{
private String club_id;
private String course_id;
}
@Entity
@Table(name="mig_course_info")
public class MigCourse {
@EmbeddedId
private MigCourseId migCourseId;
@MapsId("club_id")
@ManyToOne
@JoinColumn(name = "club_id")
private MigGolfClub migGolfClub;
}
孙
@Embeddable
public class MigHoleId implements Serializable{
private MigCourseId migCourseId;
private int hole_num;
}
@Entity
@Table(name="mig_hole_info")
public class MigHole {
@EmbeddedId
private MigHoleId migHoleId;
@MapsId("migCourseId")
@ManyToOne
@JoinColumns( {
@JoinColumn(name="club_id"),
@JoinColumn(name="course_id")
})
private MigCourse migCourse;
}
曾孙
@Embeddable
public class MigTeeId implements Serializable{
private MigHoleId migHoleId;
private String t_name;
}
@Entity
@Table(name="mig_tee_info")
public class MigTee {
@EmbeddedId
private MigTeeId migTeeId;
@MapsId("migHoleId")
@ManyToOne
@JoinColumns( {
@JoinColumn(name="club_id"),
@JoinColumn(name="course_id"),
@JoinColumn(name="hole_num")
})
private MigHole migHole;
}
我测试了并收到了错误消息
nested exception is org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: xxx.xxx.xxx.MigHole"
我和孙子(2关系)成功了,但是我和孙子(3关系)失败了
如果与复合键超过3个关系,我不能使用@EmbeddedId吗? - ;;