Thursday March 06, 2003
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 in Java
at Mar 06 2003, 04:08:14 PM MST
6 Comments
Search This Site
Recent Entries
- Wine Tasting in Napa Valley
- How to build a Shot-Ski
- Bus Project Update
- Farewell to the 2011-2012 Ski Season
- Cruising around the Western Caribbean
- Spring Break!
- A Spectacular Trip to Stockholm and Madrid
- Comparing Web Frameworks and HTML5 with Play Scala at Jfokus 2012
- Play Framework 2.0 with Peter Hilton at Jfokus
- Secure JSON Services with Play Scala and SecureSocial
Posted by Anonymous on March 06, 2003 at 06:50 PM MST #
Posted by Anonymous on March 06, 2003 at 08:49 PM MST #
Posted by Anonymous on March 07, 2003 at 02:33 AM MST #
Posted by Lance on March 07, 2003 at 08:28 AM MST #
Posted by Anonymous on March 07, 2003 at 10:22 AM 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 01:39 PM MST #