views:

128

answers:

1

We are using NHibernate in a rich client application. It is a pretty open application (the user searches for a dataset or creates a new one, changes the data and saves the data set. We leave the session open, because sometimes we have to lazy load some properties of the object (nested object structure).

This means one big problem

  • if we leave the session open, the db (MySQL) closes the connection and we are not able to find this out and it throws an exception (socket communication error) when accessing the database (we are thinking about testing the db connection before accessing the object - but this is not really optimal neither, the other option would be to set back the timeout of the db connection , but this just doesn't seem to well).

So - is it possible to reconnect the session to a new database connection ?

Another problem

  • is it possible to get an object from one session and then re-attach it to another session ? (I often hear that session.lock should work for this - but this doesn't work so well in our application - so I ended up getting a "fresh" object from the session and copy the data over manually - which is a little bit cumbersome)

Any ideas for this ?

A: 

So, now I've started to change our application design - at so far it looks like it was worth changing.

Our main problem was that we were using very long running transactions - so I've changed this to a more saner approach (using very short lived transactions) and so far it works great.

No more problems with closed connections.

bernhardrusch