- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/lara/Person.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at com.lara.Manager.main(Manager.java:15)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:549)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 7 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 39; Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)
... 8 more
<?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">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Enable Hibernate's current session context -->
<property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/lara/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Person.hbm.xml
==============
<?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">
<hibernate-mapping package="com.lara">
<class name="Person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="native" />
</id>
<property name="age"/>
<property name="firstname"/>
<property name="lastname"/>
</class>
</hibernate-mapping>
Person.java
=============
package com.lara;
public class Person {
private int id;
private String firstName;
private String lastName;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Manager.java
=============
package com.lara;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Manager {
public static void main(String[] args) {
Person p1 = new Person();
p1.setFirstName("abc");
p1.setLastName("xyz");
p1.setAge(22);
Configuration c1 = new Configuration().configure();
SessionFactory sf = c1.buildSessionFactory();
Session s1 = sf.openSession();
s1.beginTransaction();
s1.save(p1);
s1.getTransaction().commit();
s1.flush();
s1.close();
System.out.println("done");
}
}
最佳答案
错误消息说(隐藏在一个大堆栈跟踪中):
Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration"
这是因为在您的 Person.hbm.xml 文件中,您有
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/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">
这个 DOCTYPE 必须匹配根标签。
关于hibernate - org.hibernate.InvalidMappingException :Could not parse mapping document from resource com/lara/Person. hbm.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12010056/
我刚刚开始使用 Java 和 Hibernate,并且已经让一个应用程序运行起来。当我从 Eclipse 运行它时,一切都“完美”运行,但是当我使用 Eclipse 内置函数将具有依赖项的项目打包到
我正在关注this tutorial并出现上述错误。我试过this和 this但他们没有解决问题(我的模型类所在的com.spring.hibernate.model下有User.hbm.xml,类路
当我运行该项目时,出现如下异常。在我在 Hibernate 中添加 View 表之前,一切都很好,包括 Blame.hbm.xml 和其他。它可以从数据库中读取数据。异常发生在ShowOrderDao
如果这与任何现有问题重复,我很抱歉。以下是我的员工 bean。 public class Employee { private int id; private String
我知道这个问题已经被问了很多,但我几乎阅读了其中的每一个,但没有一个对我有帮助。 我正在使用 hibernate 编写 eclipse maven 项目,但出现此错误: org.hibernate.I
> 我正在使用 eclipse。我第一次尝试编写 java hibernate 程序,但出现了上述错误。请帮我解决它。 downloaded hibernate release 4.2.5 final
我在一对多映射方面遇到问题。如果我不在 .xml 文件中添加一对多映射,则一切正常。但是,当我添加一对多时,我接受了这个异常(exception)。 Exception in thread "main
我在做this tutorial 我收到以下错误: Initial SessionFactory creation failed.org.hibernate.InvalidMappingExcepti
我是 Hibernate 的初学者,无法理解我的程序的哪一部分出错了。谁能告诉我什么可能导致这种类型的错误: org.hibernate.InvalidMappingException: unable
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document f
这是我的目录结构: 以下是错误: 我正在尝试我的第一个 hibernate 程序,但收到此错误。我的程序只是在数据库中输入用户名、密码和电子邮件。我创建了一个 POJO user.java、一个 Us
这是我的 Employee.hbm.xml This class contains the employee detail.
我是 hibernate 新手当我尝试执行下面的代码时,我遇到了以下异常: org.hibernate.InvalidMappingException: 无法从资源 Employee.hbm.xml
我是一名优秀的程序员,十分优秀!