我已经对这个问题持续了好几个星期了,而且我不知道如何绕过它。
我有两张桌子:
代码:
@Entity
@IdClass(AuthorPK.class)
@Table(name="Author")
public class Author implements Serializable {
@Id
@Column(name="author_code")
private long authorCode;
@Id
@Column(name="author_number")
private String authorNumber;
@Column(name="author_name")
private String authorName;
//bi-directional many-to-one association to Title
@OneToMany(mappedBy="author")
private List<Title> titles;
//getter setters
}
public class AuthorPK implements Serializable {
private long authorCode;
private String authorNumber;
//getter equals() hashCode()
}
@Entity
@IdClass(TitlePK.class)
@Table(name="Title")
public class Title implements Serializable {
@Id
@Column(name="title_code")
private long titleCode;
@Id
@Column(name="sequence")
private long sequence;
@Column(name="title_desc")
private String titleDesc;
//bi-directional many-to-one association to Author
@ManyToOne
@JoinColumns({
@JoinColumn(name="author_code", referencedColumnName="author_code"),
@JoinColumn(name="author_number", referencedColumnName="author_number")
})
private Author author;
//getters setters
}
public class TitlePK implements Serializable {
private long titleCode;
private long sequence;
//getter equals() hashcode()
}
我需要通过author_code链接这两个实体,但是JPA要求我在@JoinColumn中包含这两个ID ...它因为源表没有其他列而在我的应用程序上抛出错误。我还有另一种方式加入这些实体吗?