如何在hibernate中将一个属性映射到2个属性?
例如:
@Entity
@Table(name = "Author")
public class ModelAuthor extends Model {
@ManyToMany(mappedBy = "authorList",
fetch = FetchType.LAZY)
private Set<ModelConceptualBook> conceptualBookList;
}
@Entity
@Table(name = "ConceptualBook")
public class ModelConceptualBook extends Model {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "ConceptualBook_Author",
joinColumns = {@JoinColumn(name = "conceptualBookId")},
inverseJoinColumns = {@JoinColumn(name = "authorId")})
private Set<ModelAuthor> authorList;
private Set<ModelAuthor> translatorList;
}
现在我想要另一张表ConceptualBook_Author
,以便将translatorList
从ModelConceptualBook
映射到conceptualBookList
ModelAuthor
,例如authorList
。
如何实现此功能?
非常感谢你的帮助;)
答案 0 :(得分:0)
只需使用其他表格 - 例如ConceptualBook_Translator
。
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "ConceptualBook_Translator",
joinColumns = {@JoinColumn(name = "conceptualBookId")},
inverseJoinColumns = {@JoinColumn(name = "authorId")})
private Set<ModelAuthor> translatorList;
另一方面关系如下:
@ManyToMany(mappedBy = "translatorList",
fetch = FetchType.LAZY)
private Set<ModelConceptualBook> booksTranslated;