【发布时间】:2009-08-03 10:28:10
【问题描述】:
是否可以在使用 3 个 PK 列的连接中使用 @ManyToMany 映射?
我相当肯定这是不可能的,解决方案是使用我过去做过的@OneToMany 公开实体,但是因为这个字段只是一个 PK,我认为可能有一些聪明的映射可以拯救我工作。
问候一个有希望的人 - JamesC
响应 ChssPly 的更新
这是我的“加入”实体的 sn-p。
@SuppressWarnings("serial")
@Embeddable
public static class Id implements Serializable {
@Column(name = StringPool.Column.APPLICATION_ID)
private Long applicationId;
@Column(name = StringPool.Column.ARTICLECATEGORY_ID)
private Long articleCategoryId;
@Column(name = StringPool.Column.USER_ID)
private Long userId;
public Id() {}
public Id(Long applicationId, Long articleCategoryId, Long userId) {
this.applicationId = applicationId;
this.articleCategoryId = articleCategoryId;
this.userId = userId;
}
public boolean equals(Object o) {
if (o instanceof Id) {
Id that = (Id)o;
return this.applicationId.equals(that.applicationId) &&
this.articleCategoryId.equals(that.articleCategoryId) &&
this.userId.equals(that.userId);
} else {
return false;
}
}
public int hashCode() {
return applicationId.hashCode() + articleCategoryId.hashCode() + userId.hashCode();
}
}
【问题讨论】: