I was playing with NHibernate's 2nd level cache, and ran into some unexpected behavior. I have a simple situation where a parent has a one-directional collection of children. I have setup the cache as read- write on both the parent and the collection.
What I do is I create the parent, add a few children and save/commit. Looking at what is happening behind the scenes, the parent is locked/ invalidated, but after the transaction commits it is inserted into the cache. On the other hand, the collection is locked/invalidated but no attempt is made to add it to the cache after the transaction commits. Looking at the code, it is clear that collections are only loaded into the cache on an a CollectionUpdateAction. With this in mind, I modified CollectionRecreateAction to have the same AfterTransactionCompletion method as the update action, and it seems to do what I expect. Is there a reason why we can't update the cache when collections are first created? Will my naive fix break something I may not be taking into consideration?
