Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Desktop App : should it use multiple sessions?

Should a NHibernate desktop app use a SessionFactory and multiple sessions ? Does the One session per transaction rule apply only to web applications ?

Regards, MadSeb

like image 781
MadSeb Avatar asked Nov 28 '25 08:11

MadSeb


1 Answers

Yes, an NHibernate desktop application should typically use multiple sessions.

In a two-tier scenario, you'll use a session per logical "session of interaction," such as a given "view" or "screen." Here you can maintain the session longer than you could in a web application, and reap the full benefit of lazy-loading, but at some point you want the user to "save" or "cancel" and move on to something else, and this is often a good place to end the session.

Using a single session throughout the application can cause a lot of stuff to be cached, and the client-side data may become stale or you could run into concurrency problems.

Furthermore, once a session encounters an exception, it is no longer valid and you'll have to abandon/reset whatever you were doing. If that is one form, it isn't a big deal, but if you have lots of objects throughout your application referencing the same session, they'll all be in a compromised state.

like image 108
Jay Avatar answered Dec 01 '25 03:12

Jay