Announcement Announcement Module
Collapse
No announcement yet.
.hbm.xml does not exist error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • .hbm.xml does not exist error

    I am building a simple spring-hibernate application.

    This is my applicationContext.xml file.

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost/db</value>
    </property>
    <property name="username">
    <value>root</value>
    </property>
    <property name="password">
    <value>madp</value>
    </property>
    </bean>


    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref local="myDataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>./WEB-INF/Login.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>hibernate.dialect=org.hibernate.dialect.MyS QLDialect</value>
    </property>
    </bean>

    <bean id="userdao" class="springapp.web.UserDAO">
    <property name="sessionFactory">
    <ref local="mySessionFactory"/>

    </property>
    </bean>

    </beans>


    This is my Login.hbm.xml file.


    <hibernate-mapping>
    <class name="springapp.web.Login" table="user">
    <id name="userId" column="id" type="int">
    <generator class="native"/>
    </id>

    <property name="userName" column="username"/>
    <property name="pwd" column="passwd"/>

    </class>

    </hibernate-mapping>


    I am getting an error that Login.hbm.xml doesnt exist.

    this is the trace ..

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/Login.hbm.xml] cannot be opened because it does not exist
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    java.security.AccessController.doPrivileged(Native Method)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:381)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 02)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:316 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:282)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:126)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    java.lang.Thread.run(Unknown Source)



    Where exactly should the .hbm.xml file be placed ? What else could be the problem ?

    Please help ..

  • #2
    Code:
    <value>./WEB-INF/Login.hbm.xml</value>
    Why is there a . (dot) at the beginning of the path?

    You can place the hbm files in /WEB-INF/ and refer to them correct just by specifying the path. Also, you can put them in your classpath (so in the src dir for your project for example) and user classpath:*.hbm I think.

    Comment


    • #3
      Well, I did try doing that...i.e placing in WEB-INF, removing the dot and specifying the path...Still the error persists...

      Comment


      • #4
        Originally posted by ankie View Post
        I am building a simple spring-hibernate application.

        This is my applicationContext.xml file.

        <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName">
        <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
        <value>jdbc:mysql://localhost/db</value>
        </property>
        <property name="username">
        <value>root</value>
        </property>
        <property name="password">
        <value>madp</value>
        </property>
        </bean>


        <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
        <property name="dataSource">
        <ref local="myDataSource"/>
        </property>
        <property name="mappingResources">
        <list>
        <value>./WEB-INF/Login.hbm.xml</value>
        </list>
        </property>
        <property name="hibernateProperties">
        <value>hibernate.dialect=org.hibernate.dialect.MyS QLDialect</value>
        </property>
        </bean>

        <bean id="userdao" class="springapp.web.UserDAO">
        <property name="sessionFactory">
        <ref local="mySessionFactory"/>

        </property>
        </bean>

        </beans>


        This is my Login.hbm.xml file.


        <hibernate-mapping>
        <class name="springapp.web.Login" table="user">
        <id name="userId" column="id" type="int">
        <generator class="native"/>
        </id>

        <property name="userName" column="username"/>
        <property name="pwd" column="passwd"/>

        </class>

        </hibernate-mapping>


        I am getting an error that Login.hbm.xml doesnt exist.

        this is the trace ..

        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/Login.hbm.xml] cannot be opened because it does not exist
        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
        java.security.AccessController.doPrivileged(Native Method)
        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
        org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
        org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
        org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
        org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
        org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
        org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:381)
        org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 02)
        org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:316 )
        org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:282)
        org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:126)
        javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
        org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
        org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
        org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
        org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
        org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
        java.lang.Thread.run(Unknown Source)



        Where exactly should the .hbm.xml file be placed ? What else could be the problem ?

        Please help ..
        copy u'r .hbm.xml files into WEB-INF/classes directory.

        Comment

        Working...
        X