I'm having a problem with this too now. But Hibernate is kicking back a totally bogus stack trace, one has very little connection to the code that is executed.
The problem that I seeing in this particular app is that I am using local configuration objects, not the JBoss service MBean. I cache the SessionFactory calling Config.buildSessionFactory(), but if the database is restarted, it starts blowing these crazy exceptions.
I'm also looking at this from an architectural perspective. Confg.buildSessionFactory() is very expensive. So I can't call it all the time. I wouldn't mind calling it if I could sense when it needed to be called (i.e. after the database connection is lost), but the exception does not happen until session.find() is called. Calling SessionFactory.openSession() succeeds just fine. If the logic required could be wrapped in a SessionFactory facade and the Session that is returned can be validated before it is used by the client, that would not be a problem, and I would welcome a suggestion for a lightweight query or connection validation routine that could be used.
Failing a good way to make sure that the Session that is returned is good, I am going to have to write global exception catcher that knows how to determine that the SessionFactory is stale, then kill the cache so that it is reloaded on the next time through.
I filed
http://opensource.atlassian.com/project ... key=HB-592 on this, feel free to close it if I am misguided again :)