何时选择多值关联与元素集合映射

何时选择多值关联与元素集合映射

本文介绍了JPA:何时选择多值关联与元素集合映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更好地理解

(1)传统的多值关系/关联

  @Entity  - > @OneToMany  - > @Entity 



嵌入式(和基本)类型的JPA2 集合

  @Entity  - > @ElementCollection  - > @Embeddable 

我看到了语法上的差异,但不知道是否也存在性能影响 EM>。在底层,数据库实现看起来非常相似。



直觉上,我通常对组合场景使用 @ElementCollection 。但即使是这样的感觉非常相似,如 CascadeType = DELETE



我在这里错过了本质吗?



谢谢J。

解决方案

也非常相似,它们是相似的,只是略有不同。 页面/ wiki / Java_Persistencerel =noreferrer> Java Persistence wikibook总结得非常好:



另请参阅






I would like to better understand the differences between

(1) a traditional Multivalued Relationship/Association

   @Entity -> @OneToMany -> @Entity

and

(2) the JPA2 Collection of Embeddable (and basic) Types

  @Entity -> @ElementCollection -> @Embeddable

I see the syntactical differences, but wonder whether there are also performance implications. Under the hood, the database implementation looks very similar.

Intuitively, I would typically use the @ElementCollection for composition scenarios. But even that feels very similar like CascadeType=DELETE.

Am I missing the essence here? Is one more efficient than the other for certain purposes?

Thank you, J.

解决方案

They are similar, with some slight differences. The ElementCollection page from the Java Persistence wikibook summarizes it pretty well:

See also

这篇关于JPA:何时选择多值关联与元素集合映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 09:13