To add more detail to my above post, what I am seeing is that the current session obtained from the above code shows that it is connected and open (when checked session.IsConnected and session.IsOpen properties). However, when a query is executed on it, the ADOException that is thrown has an inner exception Oracle.DataAccess.Client.OracleException ORA-12571: TNS:packet writer failure, indicating that the underlying oracle connection that is used is no longer valid. This is happening when I am executing a query.
What I would like to do is to have hibernate establish a new conenction and then re-execute that query again. Any suggestions on how to accomplish that? Thanks. Waqar Sadiq On Apr 16, 5:22 pm, Waqar Sadiq <[email protected]> wrote: > 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 -~----------~----~----~----~------~----~------~--~---
