2012-09-05 82 views
0

我有一個多對多的映射圖書和作者多對多映射與jointable和複合鍵

@Enity 
public class Book{ 

    private Long id; 
    private String name; 
    ... 

    @Id 
    @Column(name="book_id") 
    public getId(){ 
    ... 
    } 
    @ManyToMany(
    @JoinTable(name="book_author", 
     joinColumns = @JoinColumn(name="book_id"), 
     inverseJoinColumns = @JoinColumn(name="????") 
    ) 
    public List<Author> getAuthors(){ 
    ... 
    } 
} 

@Enity 
public class Author{ 
    @EmbeddedId; 
    private AuthorPk authorPk; 
    ... 

} 

之間我該怎麼辦是一個多對多的映射上inverseJoinColumn,因爲它是一個複合鍵?

回答

4
inverseJoinColumns = {@JoinColumn(name = "theFirstColumnInTheJoinTable", 
            referencedColumnName = "theFirstColumnInTheTargetTable"), 
         @JoinColumn(name = "theSecondColumnInTheJoinTable", 
            referencedColumnName = "theSecondColumnInTheTargetTable")} 

但我肯定會避免複合PK:他們讓生活更復雜,性能更差。