Difference between @OneToMany and @ElementCollection?

前端 未结 6 1446
不思量自难忘°
不思量自难忘° 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 03:16

    ElementCollection is a standard JPA annotation, which is now preferred over the proprietary Hibernate annotation CollectionOfElements.

    It means that the collection is not a collection of entities, but a collection of simple types (Strings, etc.) or a collection of embeddable elements (class annotated with @Embeddable).

    It also means that the elements are completely owned by the containing entities: they're modified when the entity is modified, deleted when the entity is deleted, etc. They can't have their own lifecycle.

提交回复
热议问题