1

我在书和作者之间有多对多的映射

@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

1 回答 1

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

但我肯定会避免复合 PK:它们使生活变得更加复杂,性能也更差。

于 2012-09-05T09:04:04.220 回答