SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. org.hibernate.InvalidMappingException: Could not parse mapping document from resource ./employee.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.yahoo.hibernatelearning.FirstExample.main(FirstExample.java:19) Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:555) at org.hibernate.cfg.Configuration.addResource(Configuration.java:613) ... 7 more Caused by: org.dom4j.DocumentException: http://hibernate.sourceforge.net/%0Ahibernate-mapping-3.0.dtd Nested exception: http://hibernate.sourceforge.net/%0Ahibernate-mapping-3.0.dtd at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546) ... 8 more Exception in thread "main" java.lang.NullPointerException at com.yahoo.hibernatelearning.FirstExample.main(FirstExample.java:33)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:./db/repository</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.default_schema">PUBLIC</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="./employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/
hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.yahoo.hibernatelearning.Employee" table="employee">
<id name="empId" type="int" column="emp_id" >
<generator class="native"/>
</id>
<property name="empName">
<column name="emp_name" />
</property>
<property name="empSal">
<column name="emp_sal" />
</property>
</class>
</hibernate-mapping>
package com.yahoo.hibernatelearning; public class Employee { private int empId; private String empName; private int empSal; public int getEmpId() { return empId; } public void setEmpId(int empId) { this.empId = empId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public int getEmpSal() { return empSal; } public void setEmpSal(int empSal) { this.empSal = empSal; } }
package com.yahoo.hibernatelearning; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class FirstExample { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Session sess = null; Transaction tran = null; try{ SessionFactory sessFact = new Configuration().configure().buildSessionFactory(); sess = sessFact.openSession(); System.out.println("Session: "+ sess); tran = sess.beginTransaction(); Employee emp = new Employee(); emp.setEmpName("Birendra Kumar"); emp.setEmpSal(12000); sess.save(emp); tran.commit(); } catch(Exception ex){ ex.printStackTrace(); } finally{ sess.close(); } } }
%0a
说明问题是http://hibernate.sourceforge.net/
和hibernate-mapping-3.0.dtd
之间的换行。
通过删除换行来解决问题:
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
问题内容: 我知道这已经被问过十二遍了。今天,我一定很沮丧,因为我尝试了一百种方法来修改xml文件,但我无法弄清楚。 运行驱动程序时出现错误堆栈: 这是我如何建立表格的MySQL代码: 这是我的映射文件: 这是我的配置文件: 任何帮助表示赞赏,谢谢! 一些其他信息:安装程序包test_hibernate和这是我的持久性文件: 这是我的司机: 问题答案: 您的映射文件看起来不错。我认为这可能是由于您
当我尝试用Maven编译时,我得到了这个错误: 但我看不出错误在哪里: user.java
我正在遵循本教程,并得到以上错误。我试过这个和这个,但都没有解决问题(我的模型类所在的com.spring.hibernate.model下有user.hbm.xml,而class-path(src/main/java)下有hibernate.cfg.xml文件)。有谁能帮忙吗? user.hbm.xml hibernate.cfg.xml 我正在使用mysql,这是我更新的cfg文件
Hi在运行我的java类时得到以下错误:创建会话工厂失败,出现异常org.hibernate.mappingException:无法从资源中读取映射:software.hbm.xml org.hibernate.cfg.configuration.addResource(configuration.java:485),在org.hibernate.cfg.cfiguration.parsemapp
$java-cp target/hibernateMavenmysqlxmlsample-1.0-snapshot.jar com.sample.common.app 谢了。