Announcement Announcement Module
Collapse
No announcement yet.
mapping file not found: .hbm.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mapping file not found: .hbm.xml

    Hi

    I have seen many thread in search engine for mapping file not found for hbm file.
    i am extending Hibernatedaosupport and in cfg file i have mapped hbm file. All my java files are under src folder in eclipse, xml files and properties are under conf folder which is outside of src.
    ie
    project--
    |-src
    |-conf
    |WEB-INF

    Now if I keep *.hbm.xml file under src location then it is working fine, but if I keep *.hbm.xml under conf folder( my *.cfg.xml files are kept here) then it is not loading ie it gives error message: mapping file not found: .hbm.xml.

    Is it required to keep always hbm.xml files under src folder so that it should goto classes folder or we can keep anywhere and call the *.hbm.xml file? if we can call from anywhere how to do it?

  • #2
    Try this :

    In your session factory configuration set

    Code:
    <property name="mappingDirectoryLocations">
        <list>
     	<value>/conf</value>
        </list>
     </property>
    and see what happens

    Comment


    • #3
      Still i amgetting same error:
      Caused by: org.hibernate.MappingNotFoundException: resource: conf/house.hbm.xml not found
      at org.hibernate.cfg.Configuration.addResource(Config uration.java:665)
      at org.hibernate.cfg.Configuration.parseMappingElemen t(Configuration.java:1679)
      at org.hibernate.cfg.Configuration.parseSessionFactor y(Configuration.java:1647)
      at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1626)

      my session factory given as:

      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" scope="singleton">
      <property name="configLocation" value="conf/hibernate.cfg.xml" />
      <property name="mappingDirectoryLocations">
      <list>
      <value>/conf</value>
      </list>
      </property>
      </bean>
      Originally posted by gregd View Post
      Try this :

      In your session factory configuration set

      Code:
      <property name="mappingDirectoryLocations">
          <list>
       	<value>/conf</value>
          </list>
       </property>
      and see what happens

      Comment


      • #4
        I have found solution:

        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" scope="singleton">
        <property name="configLocation" value="conf/hibernate.cfg.xml" />
        <property name="mappingResources">
        <list>
        <value>conf/house.hbm.xml</value>
        </list>
        </property>
        </bean>
        But I need to copy my conf folder to WEB-INf/classes/conf location, otherwise it throws file not found exception. Is there any way to solve this, ie without copying conf to classes location?

        Comment


        • #5
          MappingResources can only receive paths relative to your classpath.

          MappingDirectoryLocations, MappingLocations etc (see LocalSessionFactoryBean javadoc) receive parameters of type Resource. You can put there paths relative to your servlet context root and they work for a normal webapp layout. If your conf directory is under "WebContent" in eclipse (which becomes root on deployment) then it should work.

          Comment


          • #6
            If I do mapping directory location then I am getting following error:

            Caused by: org.hibernate.MappingNotFoundException: resource: house.hbm.xml not found
            at org.hibernate.cfg.Configuration.addResource(Config uration.java:665)
            at org.hibernate.cfg.Configuration.parseMappingElemen t(Configuration.java:1679)
            at org.hibernate.cfg.Configuration.parseSessionFactor y(Configuration.java:1647)
            at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1626)
            at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1600)
            My *cfg.xml file:
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.hbm2ddl.auto">update</property>
            <!-- Mapping files -->
            <mapping resource="house.hbm.xml"/>
            </session-factory>
            How to solve with MappingNotFoundException?

            only soln is give complete path for: <mapping resource="com/home/accomodation/dao/house.hbm.xml"/>.
            is it any otherway which I can get the hbm.xml file directly from conf location instead of above solution?

            Originally posted by gregd View Post
            MappingResources can only receive paths relative to your classpath.

            MappingDirectoryLocations, MappingLocations etc (see LocalSessionFactoryBean javadoc) receive parameters of type Resource. You can put there paths relative to your servlet context root and they work for a normal webapp layout. If your conf directory is under "WebContent" in eclipse (which becomes root on deployment) then it should work.
            Last edited by kasim; Apr 21st, 2010, 11:55 AM.

            Comment


            • #7
              Remove completely <mapping resource...> form your set-up
              When you use mappingDirectoryLocations in LocalSessionFactoryBean you don't need to specify any other resources explicitly.

              The directory you set will be scanned for hbm files.

              Comment


              • #8
                Originally posted by gregd View Post
                Remove completely <mapping resource...> form your set-up
                When you use mappingDirectoryLocations in LocalSessionFactoryBean you don't need to specify any other resources explicitly.

                The directory you set will be scanned for hbm files.
                you mean no need of specifying hbm file? how it will identify the hbm file if I have 10 hbm files? will it impact on perfomance?

                Comment


                • #9
                  It will scan the directiory(ies) for hbm.xml files and read them the same way as if you had explicitly listed them. I don't think performance is an issue.

                  Comment

                  Working...
                  X