NHibernate / multiple sessions and nested objects
        Posted  
        
            by bernhardrusch
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by bernhardrusch
        
        
        
        Published on 2010-04-26T06:48:19Z
        Indexed on 
            2010/04/26
            6:53 UTC
        
        
        Read the original article
        Hit count: 263
        
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 ?
© Stack Overflow or respective owner