0
是否可以在使用3個PK列的連接中使用@ManyToMany映射?使用3個ID字段在連接/鏈接表中映射ManyToMany
我相當肯定這是不可能的,解決方法是使用@OneToMany公開實體,這是我過去所做的,但因爲這個領域只是一個PK,我認爲可能有一些聰明的映射來救我這項工作。
問候充滿希望 - JamesC
更新響應ChssPly
這裏是我的 '加入' 實體的一個片段。
@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();
}
}
會提示基本上相同的東西 – 2009-08-03 21:18:28