문제

How can I map one property to 2 properties in hibernate ?
Example:

@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;
}

Now I want to have anaother table ConceptualBook_Author for mapping translatorList from ModelConceptualBook to conceptualBookList of ModelAuthor like authorList.
How can I achieve this functionality?
Thanks a lot for your help ;)

도움이 되었습니까?

해결책

By simply using other table - for example ConceptualBook_Translator.

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "ConceptualBook_Translator", 
           joinColumns = {@JoinColumn(name = "conceptualBookId")}, 
           inverseJoinColumns = {@JoinColumn(name = "authorId")})
private Set<ModelAuthor> translatorList;

And on the other side relationship is as follows:

   @ManyToMany(mappedBy = "translatorList", 
                fetch = FetchType.LAZY)
    private Set<ModelConceptualBook> booksTranslated;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top