How do you initialize Hibernate?
If you're using Hibernate in a servlet container, then you're probably using a hibernate.cfg.xml file to configure Hibernate and talk to your JNDI database connection. If you're not, you might want to consider it. My question is, where do you initialize Hibernate? In version 1.2.3, you call Hibernate.configure()
to do this, and everything will startup and be ready - providing that hibernate.cfg.xml is in your classpath (WEB-INF/classes).
// Configure Hibernate. try { Hibernate.configure(); if (log.isDebugEnabled()) { log.debug("Hibernate configuration completed..."); } } catch (HibernateException h) { h.printStackTrace(); throw new UnavailableException("Error configuring Hibernate: " + h.getMessage()); }
I've been using a StartupServlet that is set to load first, and is also responsible for putting drop-down options into the application scope. However, it has recently come to my attention that I could easily use a ServletContextListener and initialize it (and my drop-downs) in the contextInitialized() method.
So my question is - which is better? From what I can tell, they do the same thing and I've never had any issues with the StartupServlet. Can anyone offer some pros/cons to each approach? Which do you use?
Posted by Anonymous on March 07, 2003 at 12:50 AM MST #
Posted by Anonymous on March 07, 2003 at 02:49 AM MST #
Posted by Anonymous on March 07, 2003 at 08:33 AM MST #
Posted by Lance on March 07, 2003 at 02:28 PM MST #
Posted by Anonymous on March 07, 2003 at 04:22 PM MST #
Hello Everyone,
I am new to Hybernate.Iwant to use Hybernate with servlet.My Database is MySQL. i am getting error like "java.lang.NoClassDefFoundError: org/dom4j/DocumentException" while configuring sessionFactory. plz give me detail about how to do it. i am using MyEclipse IDE. if possible give me step by step details. Thanks.
Posted by sachin on January 14, 2009 at 07:39 PM MST #