What’s the difference between session.Merge and session.SaveOrUpdate?

This is from section 10.7. Automatic state detection of the Hibernate Reference Documentation: saveOrUpdate() does the following: if the object is already persistent in this session, do nothing if another object associated with the session has the same identifier, throw an exception if the object has no identifier property, save() it if the object’s identifier … Read more

What are the First and Second Level caches in (N)Hibernate?

1.1) First-level cache First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces the number of SQL queries it needs to generate within a given transaction. That is instead of updating after every … Read more

Nhibernate: How to represent Many-To-Many relationships with One-to-Many relationships?

I just come up to that question, and realized, that there is missing any answer. And it is a shame, while I do often point out this NHibernate documentation statement: 24. Best Practices Don’t use exotic association mappings. Good usecases for a real many-to-many associations are rare. Most of the time you need additional information … Read more

How to Eager Load Associations without duplication in NHibernate?

Fetching Collections is a difficult operation. It has many side effects (as you realized, when there are fetched more collections). But even with fetching one collection, we are loading many duplicated rows. In general, for collections loading, I would suggest to use the batch processing. This will execute more SQL queries… but not so much, … Read more