我正在使用hibernate进行桌面应用程序而且我遇到了这个例外:
Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Unable to read XML
Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 20; Element type "hibernate-mapping" must be declared.
这是我的配置XML文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test_hibernate</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是映射XML文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Employee" table="employee">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<property name="salary" column="salary" type="double"/>
</class>
</hibernate-mapping>
我做错了什么?
答案 0 :(得分:0)
hibernate-mapping-3.0.dtd
hibernate-core-4.3.7.Final.jar
我Employee.hbm.xml
中的您的DOCTYPE声明应如下所示
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
而不是
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
请注意3.0
和DTD
之间的//EN