- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的 Employee.hbm.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 package = "com.demo.hibernate.beans">
<class name="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="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="salary" column="salary" type="int"/>
</class>
</hibernate-mapping>
运行 hibernate 时出现以下异常
Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.demo.hibernate.beans.ManageEmployee.main(ManageEmployee.java:20)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:575)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1561)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1434)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at com.demo.hibernate.beans.ManageEmployee.main(ManageEmployee.java:17)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:514)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:572)
... 7 more
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:505)
... 8 more
可能的原因是什么?
编辑:发布员工 bean
public class Employee {
private int id;
private String firstName;
private String lastName;
private int salary;
public Employee() {}
public Employee(String fname, String lname, int salary) {
this.firstName = fname;
this.lastName = lname;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId( int id ) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName( String first_name ) {
this.firstName = first_name;
}
public String getLastName() {
return lastName;
}
public void setLastName( String last_name ) {
this.lastName = last_name;
}
public int getSalary() {
return salary;
}
public void setSalary( int salary ) {
this.salary = salary;
}
}
以及postgres中的数据库结构
create table EMPLOYEE (
id INT NOT NULL DEFAULT nextval('emp_id_seq'::regclass),
first_name VARCHAR(20) default NULL,
last_name VARCHAR(20) default NULL,
salary INT default NULL,
PRIMARY KEY (id)
);
CREATE SEQUENCE emp_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 10000
CACHE 1;
最佳答案
您的文档类型有问题。从哪里复制的?我复制了你的代码并更改了docttype。它有效。
将此用于 Hibernate DOCTYPE 3.0
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
关于java - 无法创建 sessionFactory object.org.hibernate.InvalidMappingException : Could not parse mapping document from resource Employee. hbm.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18506853/
我使用 hibernate 作为持久层来与数据库通信。我使用 maven 插件 hbm2java 来生成 dao、java、*hbm.xml 和 hibernate.cfg.xml。直到那个时候插件工
我想知道上面提到的 hibernates sessionfactory 类的两种方法之间的概念差异,如果可以通过简单的例子。 最佳答案 前者打开一个正常(有状态) session ,而后者(可能不足为
我正在关注 spring doc entry关于在独立应用程序中以编程方式设置我的应用程序上下文。 主要内容: public class Reporter { public static vo
如果我在结束时用 Session.getCurrentTransaction().commit() 关闭 session 或用 session.close() 关闭 session 会发生什么方法?
我正在尝试在我的 Spring 应用程序中使用 Hibernate 进行 Db 访问。但是现在,我收到以下错误: Could not locate SessionFactory in JNDI jav
我在基于 Java 的配置中使用 Hibernate 和 Spring。我的配置文件是这个: @Bean @Autowired public HibernateTransactionManager t
下面的代码不起作用。问题是事务没有在数据库中提交 案例1: @Transactional public void save(Person p) {
我对这两者有点困惑。据我所知,两者都返回 hibernate session ,SessionFactory.getCurrentSession()返回基于属性 的上下文 session 这是在 h
Image 错误: 1) AdminModel.java - 模型类。 2) HibernateUtil.java 促进 Hibernate DB 连接。 3) AdminDAO.java - 你们知
我遇到此错误,我找不到解决方案 我在Grails中使用postgres 这是不断发生的错误 org.springframework.beans.factory.BeanCreationExceptio
我需要 Hibernate 的一个特定功能,即 StatelessSession,为此我需要 Hibernate 的 SessionFactory。问题是我只有entityManagerFactory
我正在开发 jsf 应用程序并使用 hibernate 作为后端。我想创建 session 工厂并在整个应用程序中关闭它一次。我正在使用 util 类创建 session 工厂。 import org
我正在通过读取项目外部的属性文件来创建 session 工厂。我的属性文件如下, hibernate.connection.driver_class=com.mysql.jdbc.Driver hib
我们有一种情况,我们有多个具有相同模式的数据库,但每个数据库中的数据不同。我们正在创建一个 session 工厂来处理这个问题。 问题是我们不知道我们将连接到哪个数据库,直到运行时我们可以提供它。但是
在我的应用程序中,当我需要在这些方法中访问我的数据库时,我一直在我的方法参数中传递我的 SessionFatory。它在我的 Controller 中实例化,使用: @Autowired privat
我对 DataSource 和 SessionFactory 之间的区别感到困惑。 我认为SessionFactory是一个用于检索 session 的管理器(我猜这实际上是与数据库的连接)。 Dat
我正在尝试学习 spring 3 和 DAO 和 BO 类以及如何使用它进行 Autowiring ,我想知道这是连接 sessionFactory 的正确方法,因为我已经读到它更好地使用 publi
我正在将旧应用程序移植到 Hibernate 5,但在登录阶段遇到了问题。这是它的工作原理(我无法更改): 用户最初使用通用登录名/密码(所有用户相同)连接到 oracle DB 然后用户运行“登录”
根据文档,SessionFactory 应该是线程安全的: An ISessionFactory is threadsafe, many threads can access it concurren
如何使用 java 配置创建 SessionFactory? @Bean public SessionFactory sessionFactory(){ AnnotationSessionFa
我是一名优秀的程序员,十分优秀!