I have a web application that uses spring and nhibernate.  For
database access, we have data access objects that derive from a common
base class.  This base class in turn extends
Spring.Data.nHibernate.Support.HibernateDaoSupport class.  We have a
common method that gets the current session.  All the queries and
other operations are being performed on that ISession object.
Underneath, we are using Oracle database.

Recently, the database administrator has changed the timeout values so
the database connection times out.  So in a typical scenario, if the
application is running and the session factory singleton is created,
even though user may have logged out.  So while the user was logged
out and no activity was being performed, the database connection may
timeout.  When the user tries to login again, we try to get the
session object and then execute query on that object.  This now
results in an exception saying query could not be executed.  I think
the reason for that is that the connection had been disconnected and
hibernate tried to execute query on the closed connection.  If the
user tries to login again after the second attempt, the login goes
through - which leads me to believe either spring or nhibernate had
detected from previous failure that the connection had been closed and
re-established.

Here is the code for obtaining the current session.

public ISession CurrentSession
        {
            get
            {
                ISession session = null;
                try
                {
                    session =
HibernateTemplate.SessionFactory.GetCurrentSession();
                }
                catch (HibernateException)
                {
                    session = DoGetSession(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return session;
            }
        }

What I would like to do is to test the session to see if the
connection is alive and if not then instruct nhibernate to re-
establish.

Can somebody please provide some guidance?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to