when the contract of a set as defined in the Java Collections javadoc API suits your usecase or when the contract of a bag as defined by Hibernate's documentation suits your use case.
A cursory glance at both:
BAG
A bag is an unordered, unindexed collection which may contain the same element multiple times. The Java collections framework lacks a Bag interface, hence you have to emulate it with a List. Hibernate lets you map properties of type List or Collection with the <bag> element. Note that bag semantics are not really part of the Collection contract and they actually conflict with the semantics of the List contract (however, you can sort the bag arbitrarily, discussed later in this chapter).
SET
A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.
|