check the jar version of hibernate and compare it with DTD version inside hibernate.cfg.xml
it should match basically otherwise it can not resolve the dependencies.
Вопрос
Hi i am tying to make simple web application for user registration form using jsp and hibernate When i run my application i am getting following Exeption
MappingNotFoundException: resource: user.hbm.xml not found
Here is My code
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
**hibernate.cfg.xml**
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306/employee</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<mapping resource="hiber/user.hbm.xml"/>
</session-factory>
</hibernate-configuration>
user.hbm.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="User" table="u400">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="name"></property>
<property name="password"></property>
<property name="email"></property>
</class>
</hibernate-mapping>
project Structure is as following
Project
|
|-WebPages
|
|-src
|-hiber
| |-user.java
|-UserDao.java
|-user.hbm.xml
|-hibernate.cfg.xml
How can i remove this Exception and what should i do
Thanks in advance getting following Exception
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml
root cause
org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml
root cause
org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
Решение
check the jar version of hibernate and compare it with DTD version inside hibernate.cfg.xml
it should match basically otherwise it can not resolve the dependencies.
Другие советы
Silly mistake:- your pojo/persistent class has "User.java" name which begins with capital 'U' but the mapping file "user.hbm.xml" begins with small 'u'. Solution:- both names should be same. eg:- "User.java" and "User.hbm.xml". -- Happy Coding.
If you use Maven, put your hbm.xml
file into resource folder under:
/resource/[your package]/hbm.xml
Can you try to give full path for your user.hbm.xml in hibernate.cfg.xml.
<mapping resource="hiber/user.hbm.xml"/>
Don't use full path in mapping resource :
<mapping resource="user.hbm.xml"/>
instead of
<mapping resource="hiber/user.hbm.xml"/>
Its work for me hopefully for you.