-->
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.  [ 8 posts ] 
Author Message
 Post subject: Automatic reconnect after MYSQL restart
PostPosted: Thu Sep 25, 2003 12:53 am 
Newbie

Joined: Thu Sep 25, 2003 12:45 am
Posts: 14
Location: Hannover, Germany
Hallo,

We are using hibernate with very impressive results. Averything works fine, but we still no have a solution for this problem:

When our mysql server restarts, the application do not allow any further requests by hibernate. It seems that the sessionFactory needs to reconnect. The serverside message is:

Sep 25, 2003 6:40:51 AM net.sf.hibernate.JDBCException <init>
SEVERE: Could not execute query
java.sql.SQLException: No operations allowed after connection closed
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)


We use the following code to implenet the session factory with application scope inside an initializer servlet:

public void init(ServletConfig config) throws ServletException {
super.init(config);
...
// build a SessionFactory
sessionFactory = ds.buildSessionFactory();
...
// store session factory in application context
ServletContext app = getServletContext();
app.setAttribute("hibernate.sessionFactory", sessionFactory);
}


Top
 Profile  
 
 Post subject: Re: Automatic reconnect after MYSQL restart
PostPosted: Thu Sep 25, 2003 3:32 am 
Newbie

Joined: Thu Sep 25, 2003 12:45 am
Posts: 14
Location: Hannover, Germany
Has anyone such problems and any kind of solution? Maybe we have to use a connection pool.

Any help is welcome,

Andreas Bednarz

_________________
:-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 4:50 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
I was thinking that perhaps you have a method (a thread that sleeps, e.g.) that wakes up every few seconds and does a simple query, which you know will work, and if it fails - catch (net.sf.hibernate.JDBCException) {}

Then in catch statement, recreate the SessionFactory, as per your servlet.

That's just off the top of my head, perhaps someone can give a more direct/proper approach.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 5:02 am 
Newbie

Joined: Thu Sep 25, 2003 12:45 am
Posts: 14
Location: Hannover, Germany
Do you mean a kind of background thread which runs parallel to my servlet engine in same application context with low priority?

Andreas

_________________
:-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 5:12 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
id-on wrote:
Do you mean a kind of background thread which runs parallel to my servlet engine in same application context with low priority?

Andreas

Perhaps that. Or even, have a method that you call, perhaps like this:

Code:
public static checkSessionFactory () {

    try {
    //perform a simple query
    }
    catch (net.sf.hibernate.JDBCException) {
        SessionFactory sessionFactory = ds.buildSessionFactory();
        ...
        // store session factory in application context
        ServletContext app = getServletContext();
        app.setAttribute("hibernate.sessionFactory", sessionFactory);
    }
}

Then, just before you want to make any call to the database, simply run checkSessionFactory().

Any help? :)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 5:13 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
That should be:

Code:
public static void...

in the first line...
Wish I could edit my post. :P

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is really the job of the connection pool, not the application or Hibernate.


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Fri Sep 26, 2003 7:27 am 
Newbie

Joined: Thu Sep 25, 2003 12:45 am
Posts: 14
Location: Hannover, Germany
Thank you very much,

I decided to use the background session reconnect running as a thread. The pooling would be also fine, but we can not use it in our application.

Andreas

_________________
:-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.