Hibernate version: 2.1 final
I have a webapplication that uses two different databases.
I created two different session factories, like this:
public class ServiceLocatorTotal {
// variables
public static final ThreadLocal session = new ThreadLocal();
// methods
/**
* @return session
* @throws Exception
*/
public static Session currentSession() throws Exception {
Session s = (Session) session.get();
if (s == null) {
SessionFactory sf = new Configuration().configure("/dbTotal.cfg.xml").buildSessionFactory();
s = sf.openSession();
session.set(s);
}
return s;
}
/**
* @throws Exception
*/
public static void closeSession() throws Exception {
Session s = (Session) session.get();
session.set(null);
if (s != null) {
s.close();
}
}
}
Both use another configuration file. At first i seems to work fine. But every time i query the database, a new connection is created. This continues until no more connections can't be created.
It works fine when i use one database and one session factory. But with two, it fails. I hope someone can point me in the right direction.
|