org.hibernate.HibernateException:无法解析配置:hibernate.cfg.xml

时间:2013-07-08 05:41:00

标签: java hibernate

请帮我解决此错误。

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

我是熟悉hibernate的新手,并且很难理解错误是什么。用于休眠的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>

7 个答案:

答案 0 :(得分:1)

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

同时尝试将文档类型更改为

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

答案 1 :(得分:1)

请参阅Can't parse hibernate.cfg.xml while offline

根据您的休眠版本,hibernate可能会尝试从互联网加载DTD,同时重置连接。

答案 2 :(得分:1)

运行hibernate应用程序离线使用'hibernate-core jar'文件它会工作.. 无需更改您的Hibernate配置文件.Avvappa,BEL。

答案 3 :(得分: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>

答案 4 :(得分:0)

改变你的hiber配置,即

<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">

答案 5 :(得分:0)

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

我遇到了同样的问题。当我在网上搜索解决方案时发现这个线程有关同一问题。

我回去尝试再次运行该程序并且工作正常,所做的唯一更改是连接到Internet连接。我关闭了连接,程序再次给出了同样的错误。

我的猜测是Hibernate配置文件正在从互联网上下载DTD,当它无法这样做时,它会在创建SessionFactory对象时出错。

    <!DOCTYPE hibernate-configuration PUBLIC  
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

答案 6 :(得分:0)

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

<!DOCTYPE hibernate-configuration SYSTEM  
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
相关问题