Just before you ditch bags forever, there is a particular case 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
Collection.addAll() must always return true for a bag or
List (unlike a
Set). 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!