Difference between @OneToMany and @ElementCollection?

前端 未结 6 1462
不思量自难忘°
不思量自难忘° 2020-11-28 02:19

What is the difference between using a @OneToMany and @ElementCollection annotation since both work on the one-to-many relationship?

6条回答
  •  情话喂你
    2020-11-28 02:58

    Basic or Embedded: @ElementCollection
    Entities: @OneToMany or @ManyToMany

    @ElementCollection:

    • the relation is managed (only) by the entity in which the relation is defined
    • table contains id reference to the owning entity plus basic or embedded attributes

    @OneToMany / @ManyToMany:

    • can also be managed by the other entity
    • join table or column(s) typically contains id references only

提交回复
热议问题