There is a particular case, however, in which bags, and also lists, are much more performant than sets. For a collection with
inverse="true", the standard bidirectional one-to-many relationship idiom, for example, we can add elements to a bag or list without needing to initialize (fetch) the bag elements. This is because, unlike a
Collection.addAll() must always return true for a bag or
List. This can make the following common code much faster:
Parent p = (Parent) sess.load(Parent.class, id);
Child c = new Child();
p.getChildren().add(c); //no need to fetch the collection!