title: org.hibernate.HibernateException: /hibernate.cfg.xml not found
body: <p>I'm trying to use hibernate with spring 3 mvc but at the moment I get this exception thrown. I think I need to define my <code>hibernate.cfg.xml</code> somewhere, but not sure where?</p>
  
  <p>I basically followed this example here <a href="http://www.nabeelalimemon.com/blog/2010/05/spring-3-integrated-with-hibernate-part-a/">http://www.nabeelalimemon.com/blog/2010/05/spring-3-integrated-with-hibernate-part-a/</a> And in particularly saw this line of code there that suppose to "magically" find my hibernate.cfg file using this:</p>
  
  <pre><code>return new Configuration().configure().buildSessionFactory();
  </code></pre>
  
  <p>I'm guessing that is not correct? i currently have my hibernate.cfg file inside <code>src/com/jr/hibernate/</code></p>
  
  <p>below is my cfg file:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;!-- Database connection settings --&gt;
      &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/racingleague&lt;/property&gt;
      &lt;property name="connection.username"&gt;username&lt;/property&gt;
      &lt;property name="connection.password"&gt;password&lt;/property&gt;
      &lt;property name="hibernate.format_sql"&gt;true&lt;/property&gt;
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;!-- SQL dialect --&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;!-- Enable Hibernate's automatic session context management --&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;!-- Disable the second-level cache  --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
      &lt;!-- Drop and re-create the database schema on startup --&gt;
      &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;!--property name="hbm2ddl.auto"&gt;update&lt;/property--&gt;
      &lt;mapping resource="com/jr/model/hibernateMappings/user.hbm.xml"/&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>my hibernate utils class:</p>
  
  <pre><code>package com.jr.utils;
  
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class HibernateUtils {
  
       private static final SessionFactory sessionFactory = buildSessionFactory();
  
        public static SessionFactory buildSessionFactory() {
          try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new Configuration().configure().buildSessionFactory();
          }
          catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
          }
        }
  
  }
  </code></pre>
  
  <p>which gets called bu this abstract class:</p>
  
  <pre><code>package com.jr.db;
  
  import org.hibernate.SessionFactory;
  import org.hibernate.classic.Session;
  
  import com.jr.utils.HibernateUtils;
  
  public abstract class DbWrapper&lt;T&gt; {
  
      private static SessionFactory sessionFactory = null;
      private static Session session;
  
      public DbWrapper() {
          setSessionFactory();
      }
  
      private void setSessionFactory() {
          sessionFactory = HibernateUtils.buildSessionFactory();
          session = sessionFactory.getCurrentSession();
      }
  
      public boolean addNewItem(T dbItem) {
  
          try {
              session.getTransaction().begin();
              session.save(dbItem);
              session.getTransaction().commit();
          } catch (Exception e) {
              System.err.println("error exception when adding new item to table"
                      + e);
          } finally {
  
              session.close();
              sessionFactory.close();
          }
  
          return false;
  
      }
  
      public abstract boolean removeItem(String uid);
  
      public abstract boolean modifyItem(String uid, T item);
  
  }
  </code></pre>
  
  <p>And here is the controller that originally does some hibernate stuff:</p>
  
  <pre><code>private Logger logger = Logger.getLogger(UserController.class);
  
      private UserDb userDb;
  
  @RequestMapping(value = "/user/registerSuccess", method = RequestMethod.POST)
  public String submitRegisterForm(@Valid User user, BindingResult result) {
  
      // validate the data recieved from user
      logger.info("validate the data recieved from user");
      if (result.hasErrors()) {
          logger.info("form has "+result.getErrorCount()+" errors");
  
          return "account/createForm";
      } else{
          // if everthings ok, add user details to database
          logger.info("if everthings ok, add user details to database");
  
          userDb = new UserDb();
  
          userDb.addNewItem(user);
  
          // display success and auto log the user to the system.
          return "account/main";
      }
  
  }
  </code></pre>
  
  <p>Cheers in advance. I also have all my table hibvernate xml mappings in the same location as my hibernate.cfg.xml file</p>