From the discussion above, it should be clear that indexed collections and (usually) sets allow the most efficient operation in terms of adding, removing and updating elements.
There is, arguably, one more advantage that indexed collections have over sets for many to many associations or collections of values. Because of the structure of a Set
, Hibernate doesn't ever UPDATE
a row when an element is "changed". Changes to a Set
always work via INSERT
and DELETE
(of individual rows). Once again, this consideration does not apply to one to many associations.
After observing that arrays cannot be lazy, we would conclude that lists, maps and idbags are the most performant (non-inverse) collection types, with sets not far behind. Sets are expected to be the most common kind of collection in Hibernate applications. This is because the "set" semantics are most natural in the relational model.
However, in well-designed Hibernate domain models, we usually see that most collections are in fact one-to-many associations with inverse="true"
. For these associations, the update is handled by the many-to-one end of the association, and so considerations of collection update performance simply do not apply.