【问题标题】:"Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml"“线程“主”org.hibernate.HibernateException 中的异常:无法解析配置:hibernate.cfg.xml”
【发布时间】:2017-05-02 04:39:06
【问题描述】:

这里是新手!!!我的疑问是关于 HIBERNATE 编程,我收到了这个错误,即使经过这么多研究我也无法解决!当我第一次执行程序时,它被成功处理并且值被插入到数据库中,但是突然之间我得到了这个错误,从那以后就无法继续前进了!! PS:当我尝试在我朋友的电脑上运行相同的程序时,它可以工作:/


以下是 CONSOLE 中的错误:

Exception in thread "main" org.hibernate.Hiberna`enter code here`teException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)    
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)    
at com.snycon.hibernateEx.EmployeeAction.main(EmployeeAction.java:13)    

原因:org.dom4j.DocumentException:来自服务器的文件意外结束嵌套异常:来自服务器的文件意外结束
在 org.dom4j.io.SAXReader.read(SAXReader.java:484)
在 org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481) ... 2 更多 c


下面是我的 hibernate.cfg.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-configuration>

        <session-factory>
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="connection.url">jdbc:mysql://localhost:3306/jdbcex</property>
       <property name="connection.username">root</property>
       <property name="connection.password">root</property>
       <property name="show_sql">true</property>
       <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
       <property name="hbm2ddl.auto">update</property>
        <mapping resource="employee.hbm.xml"/>
        </session-factory>

    </hibernate-configuration>

【问题讨论】:

  • 你能粘贴你的hibernate.cfg.xml吗?看起来你做了一些意外的改变。您可以尝试还原它们并重试吗?
  • 嗨@AmitK,已经发布了配置文件..是的,我已经尝试过恢复,多次创建新的!仍然没有运气! ...我还发现 ppl 说它可能是空格的问题,所以我尝试使用从 eclipse 市场下载的 xml 编辑器创建 xml 文件..但仍然相同的错误
  • 去掉hibernate.cfg.xml中第一行开头的多余空格
  • 哎呀!实际上没有空格,我不知道,当我在这里发帖时,我的意思是在“stackoverflow”中它给了我发布的问题,所以我添加了空格,我试图分享图片..但它告诉我没有有足够的积分来分享照片!:(

标签: java hibernate hibernate.cfg.xml


【解决方案1】:

hibernate.cfg.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">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多