Originally posted by Satish Kandagadla:
Did you use the same HibernateUtil class as the one posted in the Hibernate site or you have created one of your own? can you paste the code for HibernateUtil class?
Hello,
Thank you for your reply. I have HibernateUtil class created. Here is the code:
[CODE]HibernateUtil
[QB]
public class HibernateUtil {
public static final String JNDI_SESSION_FACTORY_NAME = "...";
public static final String JNDI_CLASS = "...";
public static final String JNDI_URL = "...";
public static Configuration hibernateConfig = null;
public static SessionFactory sessionFactory = null;
/**
* Log4j logger
*/
private static Log logger = LogFactory.getLog(HibernateUtil.class);
/**
* Initialize hibernate configuration and create SessionFactory object
* @return true if success
*/
public static void setup() {
try {
// Check if the SessionFactory not exists then build it. The new SessionFactory is
// automatic binded with JNDI (see hibernate.cfg.xml)
if (getSessionFactory() == null) {
logger.info("creating hibernate session fatory...");
hibernateConfig = new Configuration().configure();
sessionFactory = hibernateConfig.buildSessionFactory();
}
}
catch (Throwable ex) {
logger.debug("HibernateUtil.setup: " + ex.getMessage());
throw new ExceptionInInitializerError(ex.getMessage());
}
}
/**
* Return the global SessionFactory
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* Close the current SessionFactory and release all resource.
* The other Functions schould not be called after calling of this function
*/
public static void shutdown () {
logger.info("close hibernate session fatory...");
if (sessionFactory != null)
sessionFactory.close();
sessionFactory = null;
hibernateConfig = null;
}
}