Solution For Nhibernate Connection Reset Problem

We have been using Nhibernate for almost 3 years with SQL server 2005 as our primary database server for our Enterprise class .Net projects. During these 3 years time we came across many hurdles in standardizing this ORM for our projects in terms of capability building among our team members, creating lot of utility & abstract classes so on and so forth.

Since we made the EAA architecture which is kind of stable, technology agonistic, comfortable in terms of team expertise, we decided to use this for a medium sized .Net project we recently bagged for which we suggested our customer to use My SQL 5.1 to save licensing cost.

During this development, we found that Nhibernate was not able to insert the child entities because it was not able to fetch the parent entity’s generated identity value (say Order & orderline, order being the parent and orderline the child). After a thorough analysis, our team member found that the Nhibernate connection is getting reset randomly (not always) before it saves the child entities. while inserting child entities the value of the parent entity’s key was 0 hence it thrown error.

To solve such issues, we added the following property into our Nhibernate.config file


The hibernate documentation states the following:

The configuration parameter hibernate.connection.release_mode is used to specify which release mode to use. The possible values: *auto (the default) – equivalent to after_transaction in the current release. It is rarely a good idea to change this default behavior as failures due to the value of this setting tend to indicate bugs and/or invalid assumptions in user code. *on_close – says to use ConnectionReleaseMode.OnClose. This setting is left for backwards compatibility, but its use is highly discouraged. …

One thought on “Solution For Nhibernate Connection Reset Problem

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s