开发者

Nhibernate bag collection when is it re-creating?

I made a lot of examples to check when bag collection is recreating during adding or removing item from collection. I read that in http://knol.google.com/k/nhibernate-chapter-16-improving-performance section 16.5.1. Taxonomy:

Bags are the worst case. Since a bag permits duplicate element values and has no index column, no primary key may be defined. NHibernate has no way of distinguishing between duplicate rows. NHibernate resolves this problem by completely removing (in a single DELETE) and recreating the collection whenever it changes. This might be very inefficient.

I made bidirectional of type one t开发者_JAVA百科o many(Person -> Addresses) and the following tests:

Test 1: Inverse= false; action=insert,update,remove,count; Collection types: Set, Bag

Result: Collections behave exactly the same!

Test 2: Inverse= true; action=insert,update,remove,count; Collection types: Set, Bag

Result: Collections behave almost the same! I only see difference in adding new item to bag collection - when i do that collection is not filled with data from db.

I was using nhibernate profiler/session statystics for analizying changes in session object and in database. But i did not see any recreating items of collection, whed did it happend? i memory?


Recreating collections applies only for entities loaded from the database. When running tests in the same session that the entities were created, NHibernate knows that the collections are empty, manipulates it in memory and saves only the final state to the database on transaction commit/session flush.

I've done similiar tests - see this blog entry for example of re-creating bag collection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜