I have a question about the performance of Hibernate collections. It is my understanding that before inserting a new record in to a "many" side of a Set or List collection, Hibernate needs to first load all the instances from the database into memory (ensure there are no duplicates for a Set and keep them in order for List). So, it therefore doesn't make sense to use Set and List for very large collections because there will be a big performance hit selecting all the rows in the child table for every insert.
What is the largest recommended collection size for Set and List given this issue? Is the recommendation to always use Bag for very large collections? Can't the Set collection be optimized by using "unique" in the database as opposed to reading the entire table into memory each time? Please let me know.
|