I am trying to optimize performance for adding data in a manytomany relationship. I was initially using a collection, but this results in a delete and reinsertion in the bridge table each time I add to the collection. I have converted to a list with an @CollectionId definition which is better as it avoids the delete/reinsert. However Hibernate is still fetching the entire collection whenever I add to the collection:
Code:
Parent p = (Parent) entityManager.find(Parent.class, id);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
entityManager.flush();
Chapter 19.5 of the hibernate docs suggests that Hibernate should avoid the collection fetch when adding to a collection with inverse="true". Is there an equivalent in JPA? I am using Seam 2.1 and am happy to use Hibernate extensions.