Hibernate Best Practices: Avoiding Many-To-Many and 'exotic' relationships

前端 未结 2 1980
独厮守ぢ
独厮守ぢ 2020-12-03 18:38

The hibernate best practices states that many-to-many associations are rare and should be avoided.

Do not use exotic association mappings:

2条回答
  •  春和景丽
    2020-12-03 19:21

    There is nothing intrinsically wrong with using @ManyToMany but in practice, you rarely have the opportunity to use it. Usually you need additional attributes on the link itself, at which point, the relationship becomes an entity of its own.

    One example from my experience was the kind of person/team relationship you described. I used a @ManyToMany at first, but had to turn it into a @OneToMany once I needed to add an effective-date on the relationship (person belongs to team at specific point in time).

提交回复
热议问题