-->
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.  [ 3 posts ] 
Author Message
 Post subject: number of connections keep growing
PostPosted: Mon Dec 06, 2004 5:04 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
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. Or can point me to an example of a webapplication witch uses more than one database.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you should use a servlet filter to manage session closing if user doesn't do it well.

take a look at open session in view wiki

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 11:34 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
anthony wrote:
you should use a servlet filter to manage session closing if user doesn't do it well.

who do you mean by user?

anthony wrote:
take a look at open session in view wiki

i will :)


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