1

请帮我解决这个错误。

org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.jbpm.db.hibernate.HibernateHelper.createConfiguration   (HibernateHelper.java:89)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getConfiguration  (DbPersistenceServiceFactory.java:75)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:104)
at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:93)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionManager(JtaDbPersistenceService.java:100)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionStatus(JtaDbPersistenceService.java:88)
at org.jbpm.persistence.jta.JtaDbPersistenceService.<init>(JtaDbPersistenceService.java:50)
at org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory.openService(JtaDbPersistenceServiceFactory.java:61)
at org.jbpm.svc.Services.getService(Services.java:160)
at org.jbpm.svc.Services.getPersistenceService(Services.java:197)
at org.jbpm.JbpmContext.getPersistenceService(JbpmContext.java:695)
at org.jbpm.JbpmContext.getJobSession(JbpmContext.java:639)
at org.jbpm.job.executor.LockMonitorThread.unlockOverdueJobs(LockMonitorThread.java:64)
at org.jbpm.job.executor.LockMonitorThread.run(LockMonitorThread.java:43)
Caused by: org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
... 15 more

我是休眠新手,很难理解错误是什么。用于休眠的 jar 文件如下

hibernate-annotations.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate3.jar

我的hibernate.cfg.xml文件是

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"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/datacenter</property>
        <property name="connection.username">root</property>
         <property name="connection.password">admin</property>  
       <!-- <property     name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 

   -->

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>      
      <property name="current_session_context_class">thread</property>
       <property name="show_MySql">TRUE</property>
       <property name="format_sql">TRUE</property>
       <!-- <property name="jboss.as.jpa.providerModule">hibernate3-  bundled</property> -->


      <property name="hibernate.hbm2ddl.auto">update</property>
             <property name="hibernate.cache.use_second_level_cache">true</property>
    <!--  <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTransla  torFactory</property> -->

       <!-- List of annotated classes-->
    <!-- Associations -->
            <!-- One to one -->
    <!-- <mapping class="Emp_Timecard" />
    <mapping class="maindoor" /> -->
    <mapping class="model.serverroom" />
    <mapping class="model.resourcelist" />
    <mapping class="model.timesheet" />
    <mapping class="model.maindoor" />
    <!-- <mapping class="timesheet" />
    <mapping class="Resource_list"/> -->


   </session-factory>
  </hibernate-configuration>
4

7 回答 7

1

请参阅离线时无法解析 hibernate.cfg.xml

根据您的休眠版本,休眠可能正在尝试从互联网加载 DTD,并且同时重置了连接。

于 2013-07-09T13:14:56.030 回答
1

我认为您在正确连接到数据库时遇到问题。您确定用户名和密码正确吗?或者您是否已经有一个名为 datacenter 的数据库?

也尝试将文档类型更改为

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
于 2013-07-08T06:30:22.250 回答
1

要离线运行休眠应用程序,请使用“休眠核心 jar”文件。它可以工作。无需更改休眠配置文件 .Avvappa,BEL。

于 2016-05-17T05:32:48.803 回答
0

如下更改您的 Hibernate 配置;

<hibernate-configuration
        xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

----------------------------to as below -------------------------------------

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.5//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
于 2014-08-17T09:13:26.577 回答
0

改变你的休眠配置,即

<hibernate-configuration
    xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
    xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

----------------------------------------如下 -------------------- ------------------

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.5//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

于 2014-08-17T09:19:20.467 回答
0

如果没有解析配置文件,只检查hibernate版本。如果是休眠 3,DTD 应该来自Sourceforge网站。如果是更高版本的 DTD 应该是

<!DOCTYPE hibernate-configuration SYSTEM  
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
于 2016-06-21T10:16:47.397 回答
0

尝试在系统连接到 Internet 时运行程序

我面临着同样的问题。当我在网上搜索解决方案时,发现这个线程与同一问题有关。

我回去尝试再次运行该程序,它可以工作,唯一的更改是连接到 Internet 连接。我关闭了连接,程序又给出了和你一样的错误。

我的猜测是 Hibernate 配置文件正在从 Internet 下载 DTD,当它失败时,它会在创建 SessionFactory 对象时出错。

    <!DOCTYPE hibernate-configuration PUBLIC  
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
于 2016-03-11T19:48:35.040 回答