title: Hibernate: How to map a *.hbm.xml file in a different folder?
body: <p>I have some *.hbm.xml files that are placed in the same folder at the hibernate.cfg.xml file. Now, I want to map some other *.hbm.xml files that are in a subfolder of this folder. How could I do it? Thanks!</p>
  
  <p>here's part of my <code>hibernate.cfg.xml</code>:</p>
  
  <pre><code>   &lt;hibernate-configuration&gt;
          &lt;session-factory name="MySessionFactory"&gt;
               &lt;!-- some hibernate properties here --&gt; 
  
               &lt;!--This below works fine--&gt;
               &lt;mapping resource="A.hbm.xml"/&gt;
  
               &lt;!--This doesn't--&gt;
               &lt;mapping resource="/dir/B.hbm.xml"/&gt;
  
          &lt;/session-factory&gt;
     &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>This is part of my Ant file:</p>
  
  <pre><code>        &lt;target name="generateHibernateSql"&gt;
  
          &lt;taskdef name="SchemaExportTask"
              classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
          &gt;
              &lt;classpath&gt;
                  &lt;pathelement location="${build.classes.main.dir}"/&gt;
                  &lt;pathelement location="${base.configuration.hibernate.dir}"/&gt;
                  &lt;path refid="build.classpath.lib"/&gt;
              &lt;/classpath&gt;
          &lt;/taskdef&gt;
  </code></pre>
  
  <p>here's my folder structure</p>
  
  <pre><code>${base.configuration.hibernate.dir}
     | hibernate.cfg.xml
     | A.hbm.xml
     |--dir
     |---| B.hbm.xml
  ${build.classes.main.dir}
  </code></pre>
  
  <p><br><br></p>
  
  <h1>[Edit]</h1>
  
  <p>I have first tried and failed as Maurice suggested, changed the line to</p>
  
  <pre><code> &lt;mapping resource="dir/B.hbm.xml"/&gt;
  </code></pre>
  
  <p>still gives the same error:</p>
  
  <pre><code>Schema text failed: Could not parse mapping document from resource dir/B.hbm.xml
  </code></pre>
  
  <p>and then I went on to try adding  into my schemaexpoert as Mark suggested. It then wouldn't even find my "A.hbm.xml" anymore. Giving off the error:</p>
  
  <pre><code>Schema text failed: Could not parse mapping document from resource A.hbm.xml
  </code></pre>
  
  <p>My SchemaExportTask now looks like:</p>
  
  <pre><code>        &lt;SchemaExportTask
              config="${base.configuration.hibernate.dir}\hibernate.cfg.xml"
              quiet="no"
              text="no"
              drop="no"
              delimiter=";"
              create="yes"
              output="${dist.database.dir}\schema-export.sql"
          &gt;
              &lt;fileset dir="${base.configuration.hibernate.dir}"&gt;
                  &lt;include name="**/*.hbm.xml"/&gt;
              &lt;/fileset&gt;
          &lt;/SchemaExportTask&gt;
  </code></pre>
  
  <p><br><br></p>
  
  <h1>[Resolved]</h1>
  
  <p>The conclusion is that I was just really stupid. It had nothing to do with being in a different directory. I got confused because I was changing two things at once testing phase and then I blamed it all on the innocent "directory change". Sorry for wasting everyone's time.</p>
  
  <p>If anyone is interested, here was what happened. I did some XSLT translation using a local DTD file, and specified the local DTD file with a relative path in my XSL file. But I put the generated hbm.xml files into a difference directory -- hence SchemaExportTask cannot find the DTD file anymore and failed to parse the new hbm.xml files. And for some stupid reason, I thought the following completely different error messages meant the same thing.... Thanks a lot to Mark for reminding me that people wrote error messages for a good reason! Adding <code>fileset</code> still doesn't work now, but I now know to read error meassages...I'm sure I'll fix it soon. =.=''</p>
  
  <pre><code>Schema text failed: resource: B.hbm.xml not found
  Schema text failed: Could not parse mapping document from resource dir/B.hbm.xml
  </code></pre>