Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySQL 5.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I am currently using a servlet to initilize my hibernate mapping file on server startup. I am using Tomcat 4.1.31. Is this an acceptable way of initializing and if so, am I missing anything in my code below? Thanks!
Code:
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.apache.log4j.Logger;
public class HibernateInitializer extends HttpServlet {
private static Logger LOG = Logger.getLogger(HibernateInitializer.class);
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
initializeHibernateSessionFactory();
}
public void initializeHibernateSessionFactory(){
LOG.info("Initializing hibernate with servlet...");
// Initialize the Hibernate Factory
Session session = null;
try {
session = HibernateHelper.getSession();
} catch (HibernateException e) {
throw new RuntimeException("Could not initiaze the Hibernate Session Factory", e);
}
finally{
try {
session.flush();
session.close();
LOG.info("Hibernate initialization complete.");
} catch (HibernateException e) {
throw new RuntimeException("Could not finish the Hibernate session after initializing", e);
}
}
}
}