-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with error recovery
PostPosted: Sun Dec 11, 2005 9:14 pm 
Newbie

Joined: Tue Nov 08, 2005 1:06 pm
Posts: 1
Hibernate version: 3.0.5

Name and version of the database you are using: MySQL 4.1.12

I am having problems getting the proper error recovery working. My code looks like this:

Code:
public List<DNIS> getDNISList( boolean deleted ) {
   String query;
      
   if( deleted ) {
      query = "from DNIS where nDNIS_Id > 0";
   } else {
      query = "from DNIS where nDNIS_Id > 0 AND bDeleted = 0";
   }

   List<DNIS> dnisList;
   try {
      dnisList = session.createQuery( query ).list();
   } catch( Exception e) {
      errorRecovery("getDNISList", e);
      dnisList = session.createQuery( query ).list();
   }         

   return dnisList;
}


protected void errorRecovery( String subName, Throwable t) {
   log.error( subName, t.getMessage() +": Error recovery in process");
   if( session != null ) {
      try {
         session.close();
         log.trace( subName, "Hibernate session closed" );
      } catch (HibernateException he1) {
         log.error( subName, he1.getMessage() + ": attempting to close session" );
      }
      session = null;
   }

   session = sessionFactory.openSession();
   log.trace( subName, "Created new session in error recovery");
}


To test my error recovery process, I've setup a test suite which calls getDNISList in a loop. I stop the code in the debugger, then kill the MySQL connection. When I restart my program, it calls getDNISList and the first call throws an exception as expected. I go through the errorRecovery subroutine and retry the query. I get the following error messages:

Code:
1211 19:52:30.521 | ERROR: [getDNISList] could not execute query: Error recovery in process
1211 19:52:30.521 | T: [getDNISList] Hibernate session closed
1211 19:52:30.521 | T: [getDNISList] Created new session in error recovery
Hibernate: select dnis0_.nDNIS_Id as nDNIS1_, dnis0_.sDNIS as sDNIS0_, dnis0_.sPhoneNumber as sPhoneNu3_0_, dnis0_.sName as sName0_, dnis0_.sHuntGroup as sHuntGroup0_, dnis0_.bDeleted as bDeleted0_, dnis0_.nScriptId as nScriptId0_ from DNIS dnis0_ where nDNIS_Id>0 and bDeleted=0
19:54:43,262  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 08003
19:54:43,272 ERROR JDBCExceptionReporter:72 - No operations allowed after connection closed.
19:54:51,203  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 08003
19:54:51,213 ERROR JDBCExceptionReporter:72 - No operations allowed after connection closed.

The stacktrace is:
org.hibernate.exception.GenericJDBCException: could not execute query
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:1596)
   at org.hibernate.loader.Loader.list(Loader.java:1577)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at com.cpt.scigames.fe.DataModel.getDNISList(DataModel.java:91)
   at com.cpt.scigames.fe.DataModel.getDNISList(DataModel.java:72)
   at com.cpt.scigames.fe.Test.listDNIS(Test.java:34)
   at com.cpt.scigames.fe.Test.testErrorRecovery(Test.java:184)
   at com.cpt.scigames.fe.Test.main(Test.java:199)
Caused by: java.sql.SQLException: No operations allowed after connection closed.
   at com.mysql.jdbc.Connection.checkClosed(Connection.java:2785)
   at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1354)
   at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1335)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
   at org.hibernate.loader.Loader.doQuery(Loader.java:390)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.doList(Loader.java:1593)
   ... 10 more


I thought the session.close() actually closed the JDBC Connection, but it appears that it does not. Can somebody point out what I'm missing or a better way to handle this? Do I need to recreate the SessionFactory?

Thanks for your help,
Dan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.