刚刚开始学Hibernate。现在遇到一个问题,无法读取映射文件:Employee.hbm.xml(Employee和我的数据库表对应)
错误提示:
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource: Employee.hbm.xml
下面提示:
Caused by: org.hibernate.MappingException: invalid mapping
Caused by: org.xml.sax.SAXParseException: Document root element "hibername-mapping", must match DOCTYPE root "hibernate-mapping".
我的实现方法非常简单,开发环境是eclipse,myeclipse,tomcat
两个配置文件hibernate.cfg.xml,Employee.hbm.xml放在eclipse包资源管理器的src目录下,通过tomcat发布后,两个配置文件在WEB-INF/classes目录下。我没有用到Spring来整合hibernate。
hibernate.cfg.xml的内容如下
- XML 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-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.url"> jdbc:mysql://localhost:3306/example </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.password">admin</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="myeclipse.connection.profile"> hibernate_mysql </property> <mapping resource="Employee.hbm.xml"></mapping> </session-factory></hibernate-configuration>
Employee.hbm.xml内容如下
- XML code
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibername-mapping package="myHibernate"> <class name="Employee" table="employee"> <id name="id"> <generator class="identity" /> </id> <property name="name"> </property> <property name="department"> </property> <property name="salary"> </property> </class></hibername-mapping>
请问各位大侠们我的错误在哪里?是不是配置文件路径错了?我该怎么改啊?是不是自动生成的HibernateSessionFactory有问题啊?
------解决方案--------------------
- XML code
<hibername-mapping package="myHibernate">