title: org.hibernate.MappingNotFoundException: resource: *hbm.xml not found
body: <p>JBoss AS 7.0.1.Final, Hibernate 3.  We have a MySQL datasource.</p>
  
  <p>I have mapping resources pointing to *hbm.xml files.  I get deployment errors that tell me 'resource: *hbm.xml not found', so entities are not being mapped correctly - this stack trace is due to the User.hbm.xml not being found,</p>
  
  <pre><code>14:44:34,654 INFO  [org.hibernate.cfg.Configuration] (MSC service thread 1-9) HHH00042:Configuring from file: hibernate.cfg.xml
  14:44:34,668 WARN  [org.hibernate.internal.util.xml.DTDEntityResolver] (MSC service thread 1-9) HHH00223:Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  14:44:34,670 INFO  [org.hibernate.cfg.Configuration] (MSC service thread 1-9) HHH00221:Reading mappings from resource: User.hbm.xml
  14:44:34,697 SEVERE [com.mycompany.myapp.common.persistence.HibernateUtil] (MSC service thread 1-9) Initial SessionFactory lookup failed.: org.hibernate.MappingNotFoundException: resource: User.hbm.xml not found
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:720) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2083) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2055) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2035) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1988) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1961) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
        at com.mycompany.myapp.common.persistence.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:42) [classes:]
        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:216) [classes:]
        at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
  
  
  14:44:34,698 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter EnterpriseSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
        at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
  
  
  14:44:34,699 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter CompanySecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
        at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
  
  
  14:44:34,701 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter StationSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
        at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
  
  
  14:44:34,702 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter StudioSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
        at com.mycompany.myapp.studio.StudioSecurityFilter.init(StudioSecurityFilter.java:46) [classes:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
  </code></pre>
  
  <p>Our project is structured like</p>
  
  <pre><code>Project
  |
  |-pom.xml
  |
  |-src
  |  |-main
  |     |-java
  |     |   |-com... businessobjects
  |     |-resources
  |     |   |-META-INF
  |     |-webapp
  |
  |-test
  </code></pre>
  
  <p>we have hibernate.cfg.xml in src/main/resources/META-INF, and various *.class and *hbm.xml in src/main/java/com/businessobjects/.  Our hibernate.cfg.xml looks like</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="datasourceName"&gt;java:jboss/datasources/MySqlDS&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;mapping resource="com/mycompany/myapp/common/businessobjects/User.hbm.xml"/&gt;
          &lt;mapping resource="com/mycompany/myapp/common/businessobjects/Company.hbm.xml"/&gt;
          &lt;mapping resource="com/mycompany/myapp/common/businessobjects/ServerSettings.hbm.xml"/&gt;
          &lt;mapping resource="com/mycompany/myapp/common/businessobjects/Station.hbm.xml"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>I've tried different paths to point to the *hbm.xml files - none seem to work.  I've even tried giving it the absolute path to the *hbm.xml files, that didn't work either.</p>
  
  <p>I've also tried copying the *hbm.xml into the same directory as hibernate.cfg.xml - that also didn't work, same error.</p>
  
  <p>Looks like it errors out at this point in the code of my HibernateUtil class</p>
  
  <pre><code>static {
      try {
          InitialContext ctx = new InitialContext();
          Configuration configuration = new Configuration();
          Properties properties = new Properties();
          sessionFactory = configuration.configure(
              new File("/path/to/src/main/resources/META-INF/hibernate.cfg.xml")
              ).buildSessionFactory();
      } catch (Throwable ex) {
          // Make sure you log the exception, as it might be swallowed
          log.error("Initial SessionFactory lookup failed.", ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  </code></pre>
  
  <p>Any ideas what's going on?  Thanks    </p>