【发布时间】:2010-12-28 20:03:07
【问题描述】:
配置文件表与特权表具有一对多关联。权限表有一个多部分键,一个 profile_id 和一个 privilege_id。我只想在 profile_id 上从 Profile 表加入 Privilege 表并取回权限集合。
在我的个人资料课程中
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "PROF_ID")
public List<ProfilePrivilegeEO> getProfilePrivileges()
{
return m_profilePrivileges;
}
我的特权班有
private ProfilePrivilegeId m_profileId;
@EmbeddedId
public ProfilePrivilegeId getProfileId()
{
return m_profileId;
}
ProfilePrivilegeId 在哪里
@Embeddable
public class ProfilePrivilegeId
implements Serializable
{
private Integer m_profileId;
private Integer m_privNumber;
@Column(name = "PROF_ID")
public Integer getProfileId()
{
return m_profileId;
}
@Column(name = "PRIV_NUM")
public Integer getPrivNumber()
{
return m_privNumber;
}
.....
}
但是,当我这样做时,静态编织器会说:
The @JoinColumns on the annotated element [method getProfilePrivileges] from the entity
class [class com.acme.ProfileEO] is incomplete. When the source entity class uses a
composite primary key, a @JoinColumn must be specified for each join column using the
@JoinColumns. Both the name and the referencedColumnName elements must be specified in
each such @JoinColumn.
但是,Profile 表不知道 privilege_ids...我不明白为什么 JPA 应该要求我指定特权表的两个键,这只是 jpa 做出的任意决定,没有正当理由。 . 我需要做什么才能让它工作? (我正在使用 EclipseLInk。)
【问题讨论】: