Intuitively, I would typically use the @ElementCollection for composition scenarios. But even that feels very similar like CascadeType=DELETE
They are similar, with some slight differences. The ElementCollection page from the Java Persistence wikibook summarizes it pretty well:
Emdedded Collections
An
ElementCollectionmapping can be
used to define a collection of
Embeddableobjects. This is not a
typical usage ofEmbeddableobjects as
the objects are not embedded in the
source object’s table, but stored in a
separate collection table. This is
similar to aOneToMany, except the
target object is anEmbeddableinstead
of anEntity. This allows collections
of simple objects to be easily
defined, without requiring the simple
objects to define anIdorManyToOne
inverse mapping.ElementCollectioncan
also override the mappings, or table
for their collection, so you can have
multiple entities reference the same
Embeddableclass, but have each store
their dependent objects in a separate
table.The limitations of using an
ElementCollectioninstead of a
OneToManyis that the target objects
cannot be queried, persisted, merged
independently of their parent object.
They are strictly privately-owned
(dependent) objects, the same as an
Embeddedmapping. Their is nocascade
option on anElementCollection, the
target objects are always persisted,
merged, removed with their parent.
ElementCollectionstill can use a
fetch type and defaults toLAZYthe
same as other collection mappings.
See also
- Embeddables (Aggregates, Composite or Component Objects)