-->
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.  [ 2 posts ] 
Author Message
 Post subject: Reconnection to database in hibernate
PostPosted: Wed Jan 30, 2013 11:25 am 
Newbie

Joined: Mon Jan 07, 2013 12:56 pm
Posts: 2
Can I do a reconnection in my execption handling to all of the database operations? Do I need to rebuild the session factory?

Example below:

public abstract class AbstractEntityDao {
...
final public List<Object[]> select(String inSql, String whereClause) {
...
Retry connection 5 times in while

while (retryConn)
{

try{
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query objQuery = session.createSQLQuery();
res = objQuery.list();

retryConn = false;

} catch (JDBCConnectionException e) {

if(numOfRetries <= 5)
{
tx.rollback();
session.close();
numOfRetries++;
retryConn = true;
}
} catch (Exception e) {
retryConn = false;
log.error(e.getMessage(), e);
}
} // end while
}

Thanks


Top
 Profile  
 
 Post subject: Re: Reconnection to database in hibernate
PostPosted: Thu Jan 31, 2013 4:48 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Such work is actually job of the connection-provider (hibernate.connection.provider_class) or DataSource and you should not take care about in your business code.For example many connection-providers do/can check their pooled connections regularily to see, if they are still alive (connected).


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

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.