Hi Mara,
I am working with Sun One Apps Server and I need to connect to a number of database SIDS with different tables. I have changed my session management class to look for a config file with a different filename.
I also place the config file within the WEB-INF/classes/etc
so: -
Session session = GDMSSession.currentSession();
...
...
GDMSSession.stopSession();
I hope this helps ........
Cheers
Jon K
-----------------------------------------------------------------------
/*
* GDMSSession.java
*
* Created on 12 February 2004, 12:30
*/
package gem.common.hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import gem.common.dao.DAOException;
import java.io.File;
import java.net.URL;
/**
This class is used to get a ThreadLocal instance of the Session class.
This design pattern is documented at:
http://hibernate.bluemars.net/42.html
@author <a href="mailto:nick@systemmobile.com">Nick Heudecker</a>
*/
public class GDMSSession {
/**
Returns the ThreadLocal Session instance. This method will initialize
the <code>SessionFactory</code> if necessary.
@return Session
@throws DAOException
*/
public static Session currentSession() throws DAOException {
Session s = (Session) session.get();
try {
if(s == null) {
if (sf == null) {
try {
cfg.configure("/etc/gdms.cfg.xml");
sf = cfg.buildSessionFactory();
}
catch(Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
s = sf.openSession();
session.set(s);
}
}
catch (HibernateException he) {
throw new DAOException(he);
}
finally { }
return s;
}
/**
Closes the session object.
@throws DAOException
*/
public static void closeSession() throws DAOException {
Session s = (Session) session.get();
session.set(null);
if(s != null) {
try {
s.close();
}
catch (HibernateException he) {
throw new DAOException(he);
}
}
}
public static final ThreadLocal session = new ThreadLocal();
private static final Configuration cfg = new Configuration();
private static SessionFactory sf;
}