Ways to release nhibernate connections: why is it recommended to use "after_transaction" in the documentation?

The hibernation documentation states the following:

The hibernate.connection.release_mode configuration parameter is used to specify the release mode. Possible values: * auto (default) - the equivalent of after_transaction in the current version. It is rarely a good idea to change this default behavior, because errors due to the value of this parameter tend to indicate errors and / or invalid assumptions in the user code. * on_close - Says to use ConnectionReleaseMode.OnClose. This option is left for backward compatibility, but its use is very discouraged ....

I created an integration test that throws a StaleObjectException, while simultaneously opening two sessions and manipulating the same object. To ensure that the test rollers return everything upon completion, the test content is placed in a TransactionScope; this leads to transaction breaks, as two sessions open the db connection against the same external transaction. I want to change the ConnectionReleaseMode default parameter to "OnClose", but as stated above, the documentation does not recommend this. Can someone explain why it is not recommended to change the default behavior?

+6
nhibernate
source share
1 answer

Good, because no one else is worried. I will try to answer this myself :-) If you use a template in which transactions are performed when the session is hosted (one transaction = one session), you can also use "OnClose". If you use templates in which your session spans multiple transactions (for example, talking on a single transaction transaction http://dotnetchris.wordpress.com/2009/01/27/conversation-per-business-transaction-using-postsharp-and- ioc / ), the use of "OnClose" will depend on temporary resources, because you do not send your connections to the connection pool when making transactions. The release mode "after_transaction" by default will free your connection when making a transaction, thereby freeing up your precious database connections.

+5
source share

All Articles