在多对多关联期间,我在使用 Hibernate 时遇到了一些麻烦:/我想让一个用户拥有他的联系人。关联表用于包含关联的创建日期及其状态(例如活动、非活动等...)
休眠版本:5.2.17
弹簧靴:2.0.5
我的班级用户:
@Entity(name = "user")
public class User implements Serializable {
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "assoc_user_user", joinColumns = {@JoinColumn(name =
"id.myself.id")}, inverseJoinColumns = {@JoinColumn(name =
"id.contact.id")})
private List<AssocUserUser> contacts;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "assoc_user_user", joinColumns = {@JoinColumn(name =
"id.contact.id")}, inverseJoinColumns = {@JoinColumn(name =
"id.myself.id")})
private List<AssocUserUser> contactOf;
}
我的协会类 AssocUserUser :
@Entity(name = "assoc_user_user")
public class AssocUserUser implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private AssocUserUserId id;
@Column(name = "creation_date", nullable = false)
private LocalDateTime creationDate;
@Column(name = "status")
@Enumerated(EnumType.STRING)
private ContactStatusEnum status;
}
我的 EmbeddedId 类 AssocUserUserId :
@Embeddable
public class AssocUserUserId implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "user_id_myself", nullable = false)
private User myself;
@ManyToOne
@JoinColumn(name = "user_id_contact", nullable = false)
private User contact;
}
我的错误:
引起:org.hibernate.AnnotationException: A Foreign keyrefering com.....AssocUserUser from com.....User 有错误的列数。应该是 2
杨__羊羊
相关分类