我一直在努力解决这个错误很长一段时间请帮助我。
我正在ERROR: HHH000196: Error parsing XML (2) : Element type "hibernate-mapping" must be declared.
请帮我解决这个问题:
我的pom.xml看起来像这样:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
我的cfg.xml标题:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
我的hbm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
<class name="com.kivar.lumina.server.segment.Segment" table="segments">
<id column="ID" name="id" type="java.lang.Long">
</id>
</class>
</hibernate-mapping>
答案 0 :(得分:4)
DTD的位置网址错误。在hbm.xml中,应使用hibernate- mapping -3.0.dtd而不是hibernate- configuration -3.0.dtd,如下所示:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
答案 1 :(得分:0)
接受答案的解决方案是安全的。当然,应该有DTD用于映射而不是配置,但URL是
自Hibernate 3.6以来。见https://developer.jboss.org/wiki/HibernateCoreMigrationGuide36